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
7
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
7
Snowboarding Saved My Software Career
metaljoe
0
4
Neurodiversity in Tech
metaljoe
0
47
Neurodiversity Lightning Talk
metaljoe
0
3
Tackling a Legacy Codebase with (Micro)Services
metaljoe
0
4
Testing Workshop - Part 1 (PyConUK 2011)
metaljoe
0
14
Testing Workshop - Part 2 (PyConUK 2011)
metaljoe
0
8
Python, DOT, and Visualising Legacy Code The Lazy Way
metaljoe
0
13
Test Driven Development (A Short Introduction)
metaljoe
0
3
Other Decks in Programming
See All in Programming
Azure OpenAI Serviceのプロンプトエンジニアリング入門
tomokusaba
3
900
Native Federation: The Future of Micro Frontends in Angular
manfredsteyer
PRO
0
110
Compose-View Interop in Practice (mDevCamp 2024)
stewemetal
0
170
Build Apps for iOS, Android & Desktop in 100% Kotlin With Compose Multiplatform (mDevCamp 2024)
zsmb
0
470
From Spring Boot 2 to Spring Boot 3 with Java 21 and Jakarta EE
ivargrimstad
0
670
単体テストを書かない技術 #phpcon_odawara
o0h
PRO
27
8.5k
Next.js App Router
quramy
12
1.9k
Sheets API使ってみた
toshi0383
2
170
効率化に挑戦してみたらモバイル開発が少し快適になった話
ryunakayama
0
140
Fragment Composition of GraphQL
quramy
13
1.5k
R言語の環境構築と基礎 Tokyo.R 112
bob3bob3
0
280
Ruby Function Composition
bkuhlmann
1
340
Featured
See All Featured
Principles of Awesome APIs and How to Build Them.
keavy
121
16k
Git: the NoSQL Database
bkeepers
PRO
423
63k
Build your cross-platform service in a week with App Engine
jlugia
226
17k
KATA
mclloyd
16
12k
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
34
8.9k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
20
1.8k
VelocityConf: Rendering Performance Case Studies
addyosmani
321
23k
Side Projects
sachag
451
41k
Optimizing for Happiness
mojombo
370
69k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
352
28k
Art, The Web, and Tiny UX
lynnandtonic
290
19k
Reflections from 52 weeks, 52 projects
jeffersonlam
345
19k
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