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
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
John Chandler
November 22, 2012
Programming
0
16
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
13
Snowboarding Saved My Software Career
metaljoe
0
11
Neurodiversity in Tech
metaljoe
0
55
Neurodiversity Lightning Talk
metaljoe
0
14
Tackling a Legacy Codebase with (Micro)Services
metaljoe
0
11
Testing Workshop - Part 1 (PyConUK 2011)
metaljoe
0
19
Testing Workshop - Part 2 (PyConUK 2011)
metaljoe
0
14
Python, DOT, and Visualising Legacy Code The Lazy Way
metaljoe
0
20
Test Driven Development (A Short Introduction)
metaljoe
0
13
Other Decks in Programming
See All in Programming
そのAIレビュー、レビューしてますか? / Are you reviewing those AI reviews?
rkaga
6
4.5k
Oxlint JS plugins
kazupon
1
810
The Past, Present, and Future of Enterprise Java
ivargrimstad
0
520
IFSによる形状設計/デモシーンの魅力 @ 慶應大学SFC
gam0022
1
300
KIKI_MBSD Cybersecurity Challenges 2025
ikema
0
1.3k
副作用をどこに置くか問題:オブジェクト指向で整理する設計判断ツリー
koxya
1
600
Fluid Templating in TYPO3 14
s2b
0
130
疑似コードによるプロンプト記述、どのくらい正確に実行される?
kokuyouwind
0
380
ThorVG Viewer In VS Code
nors
0
770
Package Management Learnings from Homebrew
mikemcquaid
0
210
なるべく楽してバックエンドに型をつけたい!(楽とは言ってない)
hibiki_cube
0
140
0→1 フロントエンド開発 Tips🚀 #レバテックMeetup
bengo4com
0
550
Featured
See All Featured
Leveraging LLMs for student feedback in introductory data science courses - posit::conf(2025)
minecr
0
140
The B2B funnel & how to create a winning content strategy
katarinadahlin
PRO
0
270
Docker and Python
trallard
47
3.7k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
234
17k
How to Think Like a Performance Engineer
csswizardry
28
2.4k
Lightning Talk: Beautiful Slides for Beginners
inesmontani
PRO
1
430
Marketing to machines
jonoalderson
1
4.6k
Mobile First: as difficult as doing things right
swwweet
225
10k
It's Worth the Effort
3n
188
29k
ラッコキーワード サービス紹介資料
rakko
1
2.2M
Fashionably flexible responsive web design (full day workshop)
malarkey
408
66k
Typedesign – Prime Four
hannesfritz
42
2.9k
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