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
17
0
Share
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
16
Snowboarding Saved My Software Career
metaljoe
0
13
Neurodiversity in Tech
metaljoe
0
60
Neurodiversity Lightning Talk
metaljoe
0
15
Tackling a Legacy Codebase with (Micro)Services
metaljoe
0
13
Testing Workshop - Part 1 (PyConUK 2011)
metaljoe
0
22
Testing Workshop - Part 2 (PyConUK 2011)
metaljoe
0
14
Python, DOT, and Visualising Legacy Code The Lazy Way
metaljoe
0
21
Test Driven Development (A Short Introduction)
metaljoe
0
14
Other Decks in Programming
See All in Programming
(Re)make Regexp in Ruby: Democratizing internals for the JIT
makenowjust
3
1.1k
【ディップ|26年新卒研修資料】OpenAPI/Swagger REST API研修
dip_tech
PRO
0
170
サークル参加から学ぶ、小さな事業の回し方
yuzneri
0
190
My daily life on Ruby
a_matsuda
3
400
AIベース静的検査器の偽陽性率を抑える工夫3選
orgachem
PRO
4
460
AI時代のエンジニアリングの原則 / Engineering Principles in the AI Era
haru860
0
1.3k
実践ハーネスエンジニアリング:ステアリングループを実例から読み解く / Practical Harness Engineering: Understanding Steering Loops Through Real-World Examples
nrslib
5
5.5k
PicoRuby for IoT: Connecting to the Cloud with MQTT
yuuu
2
780
Back to the roots of date
jinroq
0
870
ふにゃっとしない名前の付け方 〜哲学で茹で上げる、コシのあるソフトウェア設計〜
shimomura
0
120
「OSSがあるなら自作するな」は AI時代も正しいか ── Build vs Adopt の新しい判断基準
kumorn5s
7
2.7k
[BalkanRuby 2026] Drop your app/services!
palkan
2
230
Featured
See All Featured
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
254
22k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
38
2.9k
The Illustrated Children's Guide to Kubernetes
chrisshort
51
52k
It's Worth the Effort
3n
188
29k
Building Flexible Design Systems
yeseniaperezcruz
330
40k
The Impact of AI in SEO - AI Overviews June 2024 Edition
aleyda
5
1.1k
Speed Design
sergeychernyshev
33
1.7k
Highjacked: Video Game Concept Design
rkendrick25
PRO
1
360
A designer walks into a library…
pauljervisheath
211
24k
Jamie Indigo - Trashchat’s Guide to Black Boxes: Technical SEO Tactics for LLMs
techseoconnect
PRO
0
140
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
PRO
199
73k
SEO for Brand Visibility & Recognition
aleyda
0
4.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