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
13
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
12
Snowboarding Saved My Software Career
metaljoe
0
9
Neurodiversity in Tech
metaljoe
0
53
Neurodiversity Lightning Talk
metaljoe
0
12
Tackling a Legacy Codebase with (Micro)Services
metaljoe
0
10
Testing Workshop - Part 1 (PyConUK 2011)
metaljoe
0
18
Testing Workshop - Part 2 (PyConUK 2011)
metaljoe
0
13
Python, DOT, and Visualising Legacy Code The Lazy Way
metaljoe
0
19
Test Driven Development (A Short Introduction)
metaljoe
0
11
Other Decks in Programming
See All in Programming
Designing Repeatable Edits: The Architecture of . in Vim
satorunooshie
0
210
スキーマ駆動で、Zod OpenAPI Honoによる、API開発するために、Hono Takibiというライブラリを作っている
nakita628
0
330
One Enishi After Another
snoozer05
PRO
0
170
ドメイン駆動設計のエッセンス
masuda220
PRO
15
7.1k
ネストしたdata classの面倒な更新にさようなら!Lensを作って理解するArrowのOpticsの世界
shiita0903
1
210
エンジニアに事業やプロダクトを理解してもらうためにやってること
murabayashi
0
110
ノーコードからの脱出 -地獄のデスロード- / Escape from Base44
keisuke69
0
150
EMこそClaude Codeでコード調査しよう
shibayu36
0
530
The Past, Present, and Future of Enterprise Java
ivargrimstad
0
140
GC25 Recap: The Code You Reviewed is Not the Code You Built / #newt_gophercon_tour
mazrean
0
140
Module Proxyのマニアックな話 / Niche Topics in Module Proxy
kuro_kurorrr
0
480
ビルドプロセスをデバッグしよう!
yt8492
0
180
Featured
See All Featured
YesSQL, Process and Tooling at Scale
rocio
174
15k
Product Roadmaps are Hard
iamctodd
PRO
55
11k
The Cost Of JavaScript in 2023
addyosmani
55
9.1k
Building Applications with DynamoDB
mza
96
6.7k
Making Projects Easy
brettharned
120
6.4k
Building an army of robots
kneath
306
46k
Principles of Awesome APIs and How to Build Them.
keavy
127
17k
Designing for humans not robots
tammielis
254
26k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
231
54k
jQuery: Nuts, Bolts and Bling
dougneiner
65
7.9k
Thoughts on Productivity
jonyablonski
72
4.9k
Why You Should Never Use an ORM
jnunemaker
PRO
60
9.6k
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