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
18
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Regular Expressions
Internal presentation on regular expressions, 2012
John Chandler
November 22, 2012
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
17
Snowboarding Saved My Software Career
metaljoe
0
14
Neurodiversity in Tech
metaljoe
0
67
Neurodiversity Lightning Talk
metaljoe
0
17
Tackling a Legacy Codebase with (Micro)Services
metaljoe
0
14
Testing Workshop - Part 1 (PyConUK 2011)
metaljoe
0
24
Testing Workshop - Part 2 (PyConUK 2011)
metaljoe
0
16
Python, DOT, and Visualising Legacy Code The Lazy Way
metaljoe
0
23
Test Driven Development (A Short Introduction)
metaljoe
0
16
Other Decks in Programming
See All in Programming
思考垂れ流し開発 ~音声入力 × AIエージェント × 開発ハーネスによる試行錯誤~
npostring
0
880
私のClaude Code活用法 (個人開発編) - PHPerKaigi mini #4(2026/08/24)
panda_program
1
210
異なる設計思想のフレームワークを経験して得た学び
amekuhideki
2
1.5k
Go × SIMDで高速化するベクトル検索 ~ルーフラインモデルでSIMDが効く境界を探れ! ~
po3rin
1
110
[DroidKaigi 2026] Bring your own phones to Gradle Managed Devices
f2lk
0
110
【デモ】Kiroで体験する仕様駆動開発|設計からコーディングまでAIと進める開発フロー
cmkudo
0
590
PyConJP2026_wat_Python × Signal Processing: How to Draw Pictures with Sound Using Spectrogram Art
wat
0
670
From 6 People Classroom Meetup to 100 People Regional Conference / FOSS4G Hiroshima 2026
furukawayasuto
0
110
スマート反転とウェブアクセシビリティ
camiha
0
120
Press start. Python's next generation.
willingc
PRO
3
310
in-process GraphQL のすすめ #ginzajs
izumin5210
4
1.5k
ALB ログから Trace を気合で繋げる技術
fohte
7
880
Featured
See All Featured
AI in Enterprises - Java and Open Source to the Rescue
ivargrimstad
0
1.5k
Paper Plane
katiecoart
PRO
2
53k
Bootstrapping a Software Product
garrettdimon
PRO
306
120k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
360
30k
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
49
3.5k
BBQ
matthewcrist
89
10k
Leo the Paperboy
mayatellez
8
2.2k
Typedesign – Prime Four
hannesfritz
42
3.2k
How to make the Groovebox
asonas
2
2.4k
Deep Space Network (abreviated)
tonyrice
0
290
Bridging the Design Gap: How Collaborative Modelling removes blockers to flow between stakeholders and teams @FastFlow conf
baasie
0
690
The Limits of Empathy - UXLibs8
cassininazir
1
640
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