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
Go言語はstack overflowの夢を見るか?
logica0419
0
230
Writing Better Go: Lessons from 10 Code Reviews
konradreiche
0
1k
Building, Deploying, and Monitoring Ruby Web Applications with Falcon (Kaigi on Rails 2025)
ioquatix
4
2k
Advance Your Career with Open Source
ivargrimstad
0
490
Flutterで分数(Fraction)を表示する方法
koukimiura
0
130
Foundation Modelsを実装日本語学習アプリを作ってみた!
hypebeans
0
110
「ちょっと古いから」って避けてた技術書、今だからこそ読もう
mottyzzz
10
6.6k
XP, Testing and ninja testing ZOZ5
m_seki
3
620
技術的負債の正体を知って向き合う / Facing Technical Debt
irof
0
160
The Past, Present, and Future of Enterprise Java
ivargrimstad
0
320
Introducing ReActionView: A new ActionView-Compatible ERB Engine @ Kaigi on Rails 2025, Tokyo, Japan
marcoroth
3
1k
CSC509 Lecture 03
javiergs
PRO
0
330
Featured
See All Featured
Being A Developer After 40
akosma
91
590k
GitHub's CSS Performance
jonrohan
1032
470k
Context Engineering - Making Every Token Count
addyosmani
5
230
Building Adaptive Systems
keathley
43
2.8k
The World Runs on Bad Software
bkeepers
PRO
72
11k
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
30
2.9k
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
PRO
23
1.5k
Scaling GitHub
holman
463
140k
Docker and Python
trallard
46
3.6k
Fashionably flexible responsive web design (full day workshop)
malarkey
407
66k
Learning to Love Humans: Emotional Interface Design
aarron
274
41k
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
114
20k
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