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
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
20260127_試行錯誤の結晶を1冊に。著者が解説 先輩データサイエンティストからの指南書 / author's_commentary_ds_instructions_guide
nash_efp
0
930
Automatic Grammar Agreementと Markdown Extended Attributes について
kishikawakatsumi
0
180
AIによる高速開発をどう制御するか? ガードレール設置で開発速度と品質を両立させたチームの事例
tonkotsuboy_com
7
2.1k
Oxlint JS plugins
kazupon
1
830
QAフローを最適化し、品質水準を満たしながらリリースまでの期間を最短化する #RSGT2026
shibayu36
2
4.3k
Rust 製のコードエディタ “Zed” を使ってみた
nearme_tech
PRO
0
150
2026年 エンジニアリング自己学習法
yumechi
0
130
責任感のあるCloudWatchアラームを設計しよう
akihisaikeda
3
170
Amazon Bedrockを活用したRAGの品質管理パイプライン構築
tosuri13
4
260
Basic Architectures
denyspoltorak
0
660
MUSUBIXとは
nahisaho
0
130
React 19でつくる「気持ちいいUI」- 楽観的UIのすすめ
himorishige
11
6k
Featured
See All Featured
State of Search Keynote: SEO is Dead Long Live SEO
ryanjones
0
110
The State of eCommerce SEO: How to Win in Today's Products SERPs - #SEOweek
aleyda
2
9.5k
How GitHub (no longer) Works
holman
316
140k
The Hidden Cost of Media on the Web [PixelPalooza 2025]
tammyeverts
2
180
Organizational Design Perspectives: An Ontology of Organizational Design Elements
kimpetersen
PRO
1
110
Information Architects: The Missing Link in Design Systems
soysaucechin
0
770
Building the Perfect Custom Keyboard
takai
2
680
Darren the Foodie - Storyboard
khoart
PRO
2
2.4k
技術選定の審美眼(2025年版) / Understanding the Spiral of Technologies 2025 edition
twada
PRO
117
110k
Chasing Engaging Ingredients in Design
codingconduct
0
110
Being A Developer After 40
akosma
91
590k
Reflections from 52 weeks, 52 projects
jeffersonlam
356
21k
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