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
コードとあなたと私の距離 / The Distance Between Code, You, and I
hiro_y
0
210
スマホから Youtube Shortsを見られないようにする
lemolatoon
27
34k
Webサーバーサイド言語としてのRustについて
kouyuume
1
5k
퇴근 후 1억이 거래되는 서비스 만들기 | 내가 AI를 사용하는 방법
maryang
1
150
pnpm に provenance のダウングレード を検出する PR を出してみた
ryo_manba
1
170
ビルドプロセスをデバッグしよう!
yt8492
0
160
contribution to astral-sh/uv
shunsock
0
570
モテるデスク環境
mozumasu
3
1.4k
AI 駆動開発におけるコミュニティと AWS CDK の価値
konokenj
5
300
スキーマ駆動で、Zod OpenAPI Honoによる、API開発するために、Hono Takibiというライブラリを作っている
nakita628
0
330
Migration to Signals, Resource API, and NgRx Signal Store
manfredsteyer
PRO
0
130
O Que É e Como Funciona o PHP-FPM?
marcelgsantos
0
240
Featured
See All Featured
How Fast Is Fast Enough? [PerfNow 2025]
tammyeverts
2
200
Building a Modern Day E-commerce SEO Strategy
aleyda
44
7.9k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
230
22k
Building Adaptive Systems
keathley
44
2.8k
Speed Design
sergeychernyshev
32
1.2k
How STYLIGHT went responsive
nonsquared
100
5.9k
Leading Effective Engineering Teams in the AI Era
addyosmani
7
680
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
285
14k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
32
1.7k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
333
22k
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
31
2.9k
How to Ace a Technical Interview
jacobian
280
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/