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
14
Snowboarding Saved My Software Career
metaljoe
0
13
Neurodiversity in Tech
metaljoe
0
58
Neurodiversity Lightning Talk
metaljoe
0
14
Tackling a Legacy Codebase with (Micro)Services
metaljoe
0
13
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
14
Other Decks in Programming
See All in Programming
Making the RBS Parser Faster
soutaro
0
500
(Re)make Regexp in Ruby: Democratizing internals for the JIT
makenowjust
3
590
CursorとClaudeCodeとCodexとOpenCodeを実際に比較してみた
terisuke
1
490
Oxlintとeslint-plugin-react-hooks 明日から始められそう?
t6adev
0
280
PHP で mp3 プレイヤーを実装しよう
m3m0r7
PRO
0
290
ふりがな Deep Dive try! Swift Tokyo 2026
watura
0
230
属人化しないコード品質の作り方_2026.04.07.pdf
muraaano
0
230
🦞OpenClaw works with AWS
licux
1
200
YJITとZJITにはイカなる違いがあるのか?
nakiym
0
240
AIベース静的検査器の偽陽性率を抑える工夫3選
orgachem
PRO
3
350
Terraform言語の静的解析 / static analysis of Terraform language
wata727
1
110
Kingdom of the Machine
yui_knk
2
820
Featured
See All Featured
Why You Should Never Use an ORM
jnunemaker
PRO
61
9.8k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
38
2.8k
Getting science done with accelerated Python computing platforms
jacobtomlinson
2
180
Believing is Seeing
oripsolob
1
110
More Than Pixels: Becoming A User Experience Designer
marktimemedia
3
380
A Modern Web Designer's Workflow
chriscoyier
698
190k
Joys of Absence: A Defence of Solitary Play
codingconduct
1
350
16th Malabo Montpellier Forum Presentation
akademiya2063
PRO
0
110
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
55
3.3k
JAMstack: Web Apps at Ludicrous Speed - All Things Open 2022
reverentgeek
1
430
Product Roadmaps are Hard
iamctodd
PRO
55
12k
DBのスキルで生き残る技術 - AI時代におけるテーブル設計の勘所
soudai
PRO
64
54k
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