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
17
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
16
Snowboarding Saved My Software Career
metaljoe
0
13
Neurodiversity in Tech
metaljoe
0
63
Neurodiversity Lightning Talk
metaljoe
0
15
Tackling a Legacy Codebase with (Micro)Services
metaljoe
0
13
Testing Workshop - Part 1 (PyConUK 2011)
metaljoe
0
22
Testing Workshop - Part 2 (PyConUK 2011)
metaljoe
0
15
Python, DOT, and Visualising Legacy Code The Lazy Way
metaljoe
0
22
Test Driven Development (A Short Introduction)
metaljoe
0
15
Other Decks in Programming
See All in Programming
ADKを使って簡単にAIエージェントを作ってみよう
k1mu21
0
280
Lessons from Spec-Driven Development
simas
PRO
0
220
Agentic UI
manfredsteyer
PRO
0
200
act1-costs.pdf
sumedhbala
0
110
エンジニアと一緒にテストコードの設計と実装を改善した話
mototakatsu
0
220
ローカルLLMを使ってB2Bサービスを作っていての学び
yaotti
0
210
Creating Composable Callables in Contemporary C++
rollbear
0
170
不変条件と整合性境界—ビジネスが決める設計判断と実現パターン / Invariants and Consistency Boundaries
nrslib
14
5.8k
Inside Stream API
skrb
1
780
Vite+ Unified Toolchain for the Web
naokihaba
0
340
Even G2とAWSで推しのエージェントを召喚しよう!
har1101
1
120
例外の正しい扱い方 そのエラー try-catchして大丈夫?
jinwatanabe
0
280
Featured
See All Featured
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
230
23k
Heart Work Chapter 1 - Part 1
lfama
PRO
8
36k
The Illustrated Children's Guide to Kubernetes
chrisshort
51
52k
Bioeconomy Workshop: Dr. Julius Ecuru, Opportunities for a Bioeconomy in West Africa
akademiya2063
PRO
1
150
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
141
35k
Breaking role norms: Why Content Design is so much more than writing copy - Taylor Woolridge
uxyall
0
330
Chasing Engaging Ingredients in Design
codingconduct
0
230
Unsuck your backbone
ammeep
672
58k
How to build an LLM SEO readiness audit: a practical framework
nmsamuel
1
780
Leadership Guide Workshop - DevTernity 2021
reverentgeek
1
310
Context Engineering - Making Every Token Count
addyosmani
9
980
Agile that works and the tools we love
rasmusluckow
331
22k
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