Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Regular Expressions
Search
John Chandler
November 22, 2012
Programming
18
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
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
17
Snowboarding Saved My Software Career
metaljoe
0
14
Neurodiversity in Tech
metaljoe
0
68
Neurodiversity Lightning Talk
metaljoe
0
18
Tackling a Legacy Codebase with (Micro)Services
metaljoe
0
14
Testing Workshop - Part 1 (PyConUK 2011)
metaljoe
0
25
Testing Workshop - Part 2 (PyConUK 2011)
metaljoe
0
16
Python, DOT, and Visualising Legacy Code The Lazy Way
metaljoe
0
23
Test Driven Development (A Short Introduction)
metaljoe
0
16
Other Decks in Programming
See All in Programming
contenteditable と日本語入力に向き合う
colorful12
0
210
ハーネス設計入門 〜 基礎知識の整理から実務へのステップアップ 〜
kinopeee
28
34k
Web Framework Benchmark Battle 2026, Any%
a_matsuda
2
2.8k
月間100万人のサービス刷新で、 技術選定をHonoに振り切った話
yutobara
8
6.8k
Groovy as a human and AI friendly programming language
paulk
0
100
When benchmarks go bad - what I learned from measuring performance wrong
hollycummins
0
240
Event is what happens
moro
2
1.3k
Agentic Software Factoryに、すごく賢いIF文を。 / super smart IF statement into the Agentic Software Factory.
rkaga
8
2.3k
なぜCTOを降りてFDEを選んだのか?〜なぜプロダクト企業がFDEで顧客の現場に踏み込むのか〜
gonta
1
230
現場と育てるRailsモデリング 〜Spreadsheetから始めたモデル設計〜
siroemk
2
870
[2026-10-09]一枚の布で作らなくてもいい。 信頼性は「パッチワーク」で紡がれる~既存の運用と新しい可能性をつなぎ合わせてきたCREの話~
tosite
0
110
オーケストレーション記述言語 Katari
yukikurage
0
180
Featured
See All Featured
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
37
6.6k
Lightning talk: Run Django tests with GitHub Actions
sabderemane
0
300
We Are The Robots
honzajavorek
0
400
The Invisible Side of Design
smashingmag
301
52k
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
12
1.3k
Impact Scores and Hybrid Strategies: The future of link building
tamaranovitovic
0
460
Building Better People: How to give real-time feedback that sticks.
wjessup
371
20k
Bridging the Design Gap: How Collaborative Modelling removes blockers to flow between stakeholders and teams @FastFlow conf
baasie
0
740
How to audit for AI Accessibility on your Front & Back End
davetheseo
0
610
Fashionably flexible responsive web design (full day workshop)
malarkey
409
67k
The Mindset for Success: Future Career Progression
greggifford
PRO
0
540
Public Speaking Without Barfing On Your Shoes - THAT 2023
reverentgeek
1
610
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