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
54
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
14
Streaming 101
jakebathman
0
24
GitFlow and You
jakebathman
0
440
Other Decks in Programming
See All in Programming
オブジェクト指向のリ・オリエンテーション~歴史を振り返り、AI時代に向きなおる~
hanyudaeiiti
10
5.7k
二郎系ラーメンのコールで学ぶ AST 解析
memory1994
PRO
7
1.7k
PHPの次期バージョンはこの時期どうなっているのか - Internalsの開発体制について - PHPカンファレンス小田原
youkidearitai
PRO
1
180
PostmanでAPIの動作確認が楽になった話
h455h1
0
130
Code Reviews
bkuhlmann
4
880
[SF Ruby, March 2024] Rails on Wasm
palkan
0
380
FigmaとPHPで作る1ミリたりとも表示崩れしない最強の帳票印刷ソリューション
ttskch
39
18k
スクラムチームと認知負荷 - ニフティのスクラムトーク Vol2. / NIFTY Tech Talk #18
niftycorp
PRO
1
120
pixivアプリでマルチモジュールを実現するまで
gatosyocora
1
130
データアナリストが行うDatabricksを活用したETLの自動化事例
shinoa
0
260
#phpcon_odawara オープン・クローズドなテストフィクスチャを求めて / open closed test fixtures
77web
3
220
What We Can Learn From OSS
inouehi
0
400
Featured
See All Featured
Understanding Cognitive Biases in Performance Measurement
bluesmoon
6
990
Code Review Best Practice
trishagee
54
15k
The Mythical Team-Month
searls
215
42k
Become a Pro
speakerdeck
PRO
10
4.5k
Git: the NoSQL Database
bkeepers
PRO
422
63k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
226
51k
Music & Morning Musume
bryan
41
5.6k
Imperfection Machines: The Place of Print at Facebook
scottboms
258
12k
Put a Button on it: Removing Barriers to Going Fast.
kastner
58
3k
Debugging Ruby Performance
tmm1
70
11k
Typedesign – Prime Four
hannesfritz
36
2.1k
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
273
13k
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/