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
16
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
13
Snowboarding Saved My Software Career
metaljoe
0
12
Neurodiversity in Tech
metaljoe
0
55
Neurodiversity Lightning Talk
metaljoe
0
14
Tackling a Legacy Codebase with (Micro)Services
metaljoe
0
12
Testing Workshop - Part 1 (PyConUK 2011)
metaljoe
0
21
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 エージェントを超えて / beyond-local-ai-agents
gawa
1
210
生成 AI 時代のスナップショットテストってやつを見せてあげますよ(α版)
ojun9
0
320
AI時代のシステム設計:ドメインモデルで変更しやすさを守る設計戦略
masuda220
PRO
6
1.1k
Claude Code Skill入門
mayahoney
0
460
Codex の「自走力」を高める
yorifuji
0
1.3k
AI時代の脳疲弊と向き合う ~言語学としてのPHP~
sakuraikotone
1
1.8k
RailsのValidatesをSwift Macrosで再現してみた
hokuron
0
140
Goの型安全性で実現する複数プロダクトの権限管理
ishikawa_pro
2
1.4k
OTP を自動で入力する裏技
megabitsenmzq
0
130
年間50登壇、単著出版、雑誌寄稿、Podcast出演、YouTube、CM、カンファレンス主催……全部やってみたので面白さ等を比較してみよう / I’ve tried them all, so let’s compare how interesting they are.
nrslib
4
610
野球解説AI Agentを開発してみた - 2026/02/27 LayerX社内LT会資料
shinyorke
PRO
0
380
AI Assistants for YourAngular Solutions @Angular Graz, March 2026
manfredsteyer
PRO
0
130
Featured
See All Featured
Public Speaking Without Barfing On Your Shoes - THAT 2023
reverentgeek
1
350
The AI Search Optimization Roadmap by Aleyda Solis
aleyda
1
5.5k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
162
16k
Optimizing for Happiness
mojombo
378
71k
Building Flexible Design Systems
yeseniaperezcruz
330
40k
Done Done
chrislema
186
16k
The Illustrated Children's Guide to Kubernetes
chrisshort
51
52k
The AI Revolution Will Not Be Monopolized: How open-source beats economies of scale, even for LLMs
inesmontani
PRO
3
3.2k
The Impact of AI in SEO - AI Overviews June 2024 Edition
aleyda
5
780
Making the Leap to Tech Lead
cromwellryan
135
9.8k
The MySQL Ecosystem @ GitHub 2015
samlambert
251
13k
Beyond borders and beyond the search box: How to win the global "messy middle" with AI-driven SEO
davidcarrasco
3
98
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