Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Regex 201
Search
Jake Bathman
December 21, 2018
Programming
0
58
Regex 201
A few quick tips on Regex for experienced peeps, given as a Tighten Talk on Dec 21, 2018
Jake Bathman
December 21, 2018
Tweet
Share
More Decks by Jake Bathman
See All by Jake Bathman
Delete Your Data
jakebathman
0
19
Streaming 101
jakebathman
0
27
GitFlow and You
jakebathman
0
480
Other Decks in Programming
See All in Programming
2025 年のコーディングエージェントの現在地とエンジニアの仕事の変化について
azukiazusa1
24
12k
HTMLの品質ってなんだっけ? “HTMLクライテリア”の設計と実践
unachang113
4
3k
250830 IaCの選定~AWS SAMのLambdaをECSに乗り換えたときの備忘録~
east_takumi
0
400
Zendeskのチケットを Amazon Bedrockで 解析した
ryokosuge
3
320
「手軽で便利」に潜む罠。 Popover API を WCAG 2.2の視点で安全に使うには
taitotnk
0
880
Putting The Genie in the Bottle - A Crash Course on running LLMs on Android
iurysza
0
140
Testing Trophyは叫ばない
toms74209200
0
890
GitHubとGitLabとAWS CodePipelineでCI/CDを組み比べてみた
satoshi256kbyte
4
250
アルテニア コンサル/ITエンジニア向け 採用ピッチ資料
altenir
0
110
AWS発のAIエディタKiroを使ってみた
iriikeita
1
190
個人開発で徳島大学生60%以上の心を掴んだアプリ、そして手放した話
akidon0000
1
160
そのAPI、誰のため? Androidライブラリ設計における利用者目線の実践テクニック
mkeeda
2
3k
Featured
See All Featured
Code Review Best Practice
trishagee
71
19k
Measuring & Analyzing Core Web Vitals
bluesmoon
9
590
Typedesign – Prime Four
hannesfritz
42
2.8k
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
127
53k
Building Flexible Design Systems
yeseniaperezcruz
329
39k
The Language of Interfaces
destraynor
161
25k
We Have a Design System, Now What?
morganepeng
53
7.8k
Build The Right Thing And Hit Your Dates
maggiecrowley
37
2.9k
Fashionably flexible responsive web design (full day workshop)
malarkey
407
66k
Rails Girls Zürich Keynote
gr2m
95
14k
The Pragmatic Product Professional
lauravandoore
36
6.9k
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
8
930
Transcript
https://dev.to/rly
TOPICS • Anchors • Match groups • Lookahead and lookbehind
ANCHORS ^ $ \b Start of string End of string
Word boundary ^([\w]+)\b([\w]+)$ Jake Bathman
MATCH GROUPS • In PHP, Javascript, and other languages, you
can name your match groups in regex matches /Call me (?<firstname>[\w]+)/ Call me Jake PHP & JS syntax: PHP example: preg_match( '/Call me (?<firstname>[\w]+)/', "Call me Jake", $matches ); echo($matches['firstname']);
LOOK AHEAD/BEHIND (?=foo) Lookahead Lookbehind Positive Negative (?!foo) (?<!foo) (?<=foo)
LOOK AHEAD/BEHIND (?=foo) Lookahead Lookbehind Positive Negative (?!foo) (?<!foo) (?<=foo)
/foo(?=bar)/ foobar foobaz ✅ ❌
LOOK AHEAD/BEHIND (?=foo) Lookahead Lookbehind Positive Negative (?!foo) (?<!foo) (?<=foo)
/foo(?!bar)/ foobar foobaz ✅ ❌
LOOK AHEAD/BEHIND (?=foo) Lookahead Lookbehind Positive Negative (?!foo) (?<!foo) (?<=foo)
/(?<=foo)bar/ foobar fuubar ✅ ❌
LOOK AHEAD/BEHIND (?=foo) Lookahead Lookbehind Positive Negative (?!foo) (?<!foo) (?<=foo)
/(?<!not )foo/ not foo but foo ✅ ❌
BONUS: MY MOST INSANE REGEX (^([A-Za-z0-9]+)\:?)|(inet|inet6)\s*(?:addr:?)?\s*((\d{1,3}\.){3}\d{1,3}|((([0-9A-Fa-f]{1,4}:){7}([0-9A- Fa-f]{1,4}|:))|(([0-9A-Fa-f]{1,4}:){6}(:[0-9A-Fa-f]{1,4}|((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9]) (\.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])){3})|:))|(([0-9A-Fa-f]{1,4}:){5}(((:[0-9A-Fa-f]{1,4}) {1,2})|:((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])(\.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])) {3})|:))|(([0-9A-Fa-f]{1,4}:){4}(((:[0-9A-Fa-f]{1,4}){1,3})|((:[0-9A-Fa-f]{1,4})?:((25[0-5]|2[0-4][0-9]|
1[0-9][0-9]|[1-9]?[0-9])(\.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])){3}))|:))|(([0-9A-Fa-f]{1,4}:) {3}(((:[0-9A-Fa-f]{1,4}){1,4})|((:[0-9A-Fa-f]{1,4}){0,2}:((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9]) (\.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])){3}))|:))|(([0-9A-Fa-f]{1,4}:){2}(((:[0-9A-Fa-f]{1,4}) {1,5})|((:[0-9A-Fa-f]{1,4}){0,3}:((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])(\.(25[0-5]|2[0-4][0-9]| 1[0-9][0-9]|[1-9]?[0-9])){3}))|:))|(([0-9A-Fa-f]{1,4}:){1}(((:[0-9A-Fa-f]{1,4}){1,6})|((:[0-9A-Fa-f] {1,4}){0,4}:((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])(\.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]? [0-9])){3}))|:))|(:(((:[0-9A-Fa-f]{1,4}){1,7})|((:[0-9A-Fa-f]{1,4}){0,5}:((25[0-5]|2[0-4][0-9]|1[0-9] [0-9]|[1-9]?[0-9])(\.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])){3}))|:)))(%.+)?) eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 45.56.76.94 netmask 255.255.255.0 broadcast 45.56.76.255 inet6 fe80::f03c:91ff:fea1:e9d1 prefixlen 64 scopeid 0x20<link> inet6 2600:3c00::f03c:91ff:fea1:e9d1 prefixlen 64 scopeid 0x0<global> ether f2:3c:91:a1:e9:d1 txqueuelen 1000 (Ethernet) RX packets 145749659 bytes 171250537930 (159.4 GiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 60215383 bytes 12025642918 (11.1 GiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 eth0: inet 45.56.76.94 inet6 fe80::f03c:91ff:fea1:e9d1 inet6 2600:3c00::f03c:91ff:fea1:e9d1 ifconfig myip
RESOURCES • Regex101 (make an account and save your stuff!)
https://regex101.com/