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
Regular Expressions
Search
John Chandler
November 22, 2012
Programming
0
12
Regular Expressions
Internal presentation on regular expressions, 2012
John Chandler
November 22, 2012
Tweet
Share
More Decks by John Chandler
See All by John Chandler
Everything I've Learnt from Russel Winder's Talks, in 5 Minutes (A Tribute)
metaljoe
0
11
Snowboarding Saved My Software Career
metaljoe
0
7
Neurodiversity in Tech
metaljoe
0
52
Neurodiversity Lightning Talk
metaljoe
0
10
Tackling a Legacy Codebase with (Micro)Services
metaljoe
0
6
Testing Workshop - Part 1 (PyConUK 2011)
metaljoe
0
17
Testing Workshop - Part 2 (PyConUK 2011)
metaljoe
0
12
Python, DOT, and Visualising Legacy Code The Lazy Way
metaljoe
0
17
Test Driven Development (A Short Introduction)
metaljoe
0
10
Other Decks in Programming
See All in Programming
20250628_非エンジニアがバイブコーディングしてみた
ponponmikankan
0
690
XP, Testing and ninja testing
m_seki
3
250
地方に住むエンジニアの残酷な現実とキャリア論
ichimichi
5
1.5k
プロダクト志向なエンジニアがもう一歩先の価値を目指すために意識したこと
nealle
0
130
#QiitaBash MCPのセキュリティ
ryosukedtomita
1
1.3k
ニーリーにおけるプロダクトエンジニア
nealle
0
840
git worktree × Claude Code × MCP ~生成AI時代の並列開発フロー~
hisuzuya
1
570
Rails Frontend Evolution: It Was a Setup All Along
skryukov
0
140
初学者でも今すぐできる、Claude Codeの生産性を10倍上げるTips
s4yuba
16
11k
AI コーディングエージェントの時代へ:JetBrains が描く開発の未来
masaruhr
1
160
明示と暗黙 ー PHPとGoの インターフェイスの違いを知る
shimabox
2
510
『自分のデータだけ見せたい!』を叶える──Laravel × Casbin で複雑権限をスッキリ解きほぐす 25 分
akitotsukahara
2
640
Featured
See All Featured
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
8
690
Site-Speed That Sticks
csswizardry
10
690
The Language of Interfaces
destraynor
158
25k
Java REST API Framework Comparison - PWX 2021
mraible
31
8.7k
How STYLIGHT went responsive
nonsquared
100
5.6k
A Modern Web Designer's Workflow
chriscoyier
695
190k
Balancing Empowerment & Direction
lara
1
430
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
PRO
181
54k
The Cost Of JavaScript in 2023
addyosmani
51
8.5k
Build The Right Thing And Hit Your Dates
maggiecrowley
36
2.8k
Why Our Code Smells
bkeepers
PRO
336
57k
Adopting Sorbet at Scale
ufuk
77
9.5k
Transcript
© John Chandler 2012 Regular Expressions
http://xkcd.com/208/
What? A pattern describing a set of text strings
When? From formal regular set theory in 1950s Popularised by
beardy UNIX types in 1970s
Why? Matching / searching text Search and replace Parsing strings
Main Flavours POSIX Basic / Extended (default with UNIX tools)
Perl-derived – very popular! (Perl, Python, PHP, JavaScript, .NET)
Syntax: The First 90% c standard characters . any character
^ start of string $ end of string c* zero or more of c
Syntax: The First 90% ^Pip*e.*$ matches: Piper at the Gates
of Dawn Pie and Chips
Syntax: The First 90% ^Pip*e.*$ doesn't match: A Pipe pie
spam chips and spam
Choices | or, alternative [abc] character class [^abc] inverse of
class
Choices foo|bar matches: foo fighters toolbar bar fool
Special Sequences \b beginning / end of word \d decimal
digit \s whitespace \w alphanumeric and underscore
Repetition s * zero or more + one or more
? zero or one {n} exactly n-times {n,m} n to m times
Groups (abc) capturing group (?:abc) non-capturing group (?P<name>) named capturing
group (?P=name) match a previous match
What do these do? (foo|bar) ((?:abc){3,4}) (?P<foo>\w+) [“']([^”']+)[“']
What about these? (fish) \1 (?P<thing>fish) (?P=thing) Isaac (?=Asimov) Isaac
(?!Asimov)
Greedy Matching By default, regular expressions are greedy. They will
find the biggest match that satisfies an expression.
Non-greedy Repetitions *? zero or more +? one or more
?? zero or one
Writing Regexes Don't if there is a simpler way Build
regex from small chunks Use the Python and PHP REPLs Document!
Debugging Regexes Don't panic Break regex into smaller chunks Use
the Python and PHP REPLs Watch out for special characters!
Anything else? Any questions? Read the Python and PHP docs
Try the UNIX grep command