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
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
61
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
Old Dog, New Tricks: The Java 25 Reinvention - JNation
bazlur_rahman
0
140
気づいたらRubyで100作品 ー クリエイティブコーディングが生活の一部になるまで / 100 Ruby Sketches Later: How Creative Coding Became Part of My Life
chobishiba
3
540
JavaDoc 再入門
nagise
0
270
並列実装の現場、2ヶ月間実務でAIを使い倒したAIもPCも私も限界が近い
ming_ayami
0
100
ReactとSvelteのその先、Ripple-TS / Beyond React and Svelte: Ripple-TS
ssssota
3
2k
net-httpのHTTP/2対応について
naruse
0
430
3Dシーンの圧縮
fadis
1
590
メソッドのジェネリクスでGoの夢は広がるか? / Kyoto.go #65
utgwkk
3
460
AIチームを指揮するOSS「TAKT」活用術 / How to Use “TAKT,” an OSS Tool for Orchestrating AI Teams
nrslib
6
810
AI駆動開発勉強会 広島支部 第一回勉強会 AI駆動開発概要とワークショップ
hayatoshimiu
0
440
正しくソフトウェアを作る、前提を疑うための認知の視点 / doubt-premise
minodriven
17
5.7k
oxlintはeslint/typescript-eslintを置き換えられるのか
shomafujita
2
310
Featured
See All Featured
Making Projects Easy
brettharned
120
6.7k
Lightning Talk: Beautiful Slides for Beginners
inesmontani
PRO
2
570
Deep Space Network (abreviated)
tonyrice
0
160
Primal Persuasion: How to Engage the Brain for Learning That Lasts
tmiket
0
360
SEO in 2025: How to Prepare for the Future of Search
ipullrank
3
3.5k
Bridging the Design Gap: How Collaborative Modelling removes blockers to flow between stakeholders and teams @FastFlow conf
baasie
0
580
WENDY [Excerpt]
tessaabrams
11
38k
Collaborative Software Design: How to facilitate domain modelling decisions
baasie
1
230
Taking LLMs out of the black box: A practical guide to human-in-the-loop distillation
inesmontani
PRO
3
2.3k
What does AI have to do with Human Rights?
axbom
PRO
1
2.2k
Become a Pro
speakerdeck
PRO
31
6k
How To Speak Unicorn (iThemes Webinar)
marktimemedia
1
480
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