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
57
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
17
Streaming 101
jakebathman
0
26
GitFlow and You
jakebathman
0
480
Other Decks in Programming
See All in Programming
PHPで始める振る舞い駆動開発(Behaviour-Driven Development)
ohmori_yusuke
2
180
Deep Dive into ~/.claude/projects
hiragram
7
1.3k
F#で自在につくる静的ブログサイト - 関数型まつり2025
pizzacat83
0
310
C++20 射影変換
faithandbrave
0
520
型付きアクターモデルがもたらす分散シミュレーションの未来
piyo7
0
810
なぜ適用するか、移行して理解するClean Architecture 〜構造を超えて設計を継承する〜 / Why Apply, Migrate and Understand Clean Architecture - Inherit Design Beyond Structure
seike460
PRO
1
660
「ElixirでIoT!!」のこれまでとこれから
takasehideki
0
370
iOSアプリ開発で 関数型プログラミングを実現する The Composable Architectureの紹介
yimajo
2
210
プロダクト志向なエンジニアがもう一歩先の価値を目指すために意識したこと
nealle
0
110
Create a website using Spatial Web
akkeylab
0
300
Rubyでやりたい駆動開発 / Ruby driven development
chobishiba
1
360
Cline指示通りに動かない? AI小説エージェントで学ぶ指示書の書き方と自動アップデートの仕組み
kamomeashizawa
1
570
Featured
See All Featured
Mobile First: as difficult as doing things right
swwweet
223
9.7k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
48
5.4k
StorybookのUI Testing Handbookを読んだ
zakiyama
30
5.8k
Why Our Code Smells
bkeepers
PRO
337
57k
Stop Working from a Prison Cell
hatefulcrawdad
270
20k
The World Runs on Bad Software
bkeepers
PRO
69
11k
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
15
1.5k
Build The Right Thing And Hit Your Dates
maggiecrowley
36
2.8k
How to Ace a Technical Interview
jacobian
277
23k
Code Reviewing Like a Champion
maltzj
524
40k
Principles of Awesome APIs and How to Build Them.
keavy
126
17k
A designer walks into a library…
pauljervisheath
206
24k
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/