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
0
11
Regular Expressions
Internal presentation on regular expressions, 2012
John Chandler
November 22, 2012
Tweet
Share
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
11
Snowboarding Saved My Software Career
metaljoe
0
7
Neurodiversity in Tech
metaljoe
0
52
Neurodiversity Lightning Talk
metaljoe
0
10
Tackling a Legacy Codebase with (Micro)Services
metaljoe
0
6
Testing Workshop - Part 1 (PyConUK 2011)
metaljoe
0
17
Testing Workshop - Part 2 (PyConUK 2011)
metaljoe
0
12
Python, DOT, and Visualising Legacy Code The Lazy Way
metaljoe
0
17
Test Driven Development (A Short Introduction)
metaljoe
0
9
Other Decks in Programming
See All in Programming
ニーリーにおけるプロダクトエンジニア
nealle
0
140
イベントストーミング図からコードへの変換手順 / Procedure for Converting Event Storming Diagrams to Code
nrslib
1
320
「Cursor/Devin全社導入の理想と現実」のその後
saitoryc
0
140
つよそうにふるまい、つよい成果を出すのなら、つよいのかもしれない
irof
1
300
Composerが「依存解決」のためにどんな工夫をしているか #phpcon
o0h
PRO
1
210
Deep Dive into ~/.claude/projects
hiragram
7
1.3k
Result型で“失敗”を型にするPHPコードの書き方
kajitack
4
290
Kotlin エンジニアへ送る:Swift 案件に参加させられる日に備えて~似てるけど色々違う Swift の仕様 / from Kotlin to Swift
lovee
1
250
Google Agent Development Kit でLINE Botを作ってみた
ymd65536
2
140
What Spring Developers Should Know About Jakarta EE
ivargrimstad
0
220
Effect の双対、Coeffect
yukikurage
5
1.4k
明示と暗黙 ー PHPとGoの インターフェイスの違いを知る
shimabox
2
290
Featured
See All Featured
How to train your dragon (web standard)
notwaldorf
92
6.1k
Building an army of robots
kneath
306
45k
Rebuilding a faster, lazier Slack
samanthasiow
81
9k
A Modern Web Designer's Workflow
chriscoyier
693
190k
Statistics for Hackers
jakevdp
799
220k
Building Applications with DynamoDB
mza
95
6.5k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
228
22k
How To Stay Up To Date on Web Technology
chriscoyier
790
250k
Automating Front-end Workflow
addyosmani
1370
200k
Art, The Web, and Tiny UX
lynnandtonic
299
21k
What's in a price? How to price your products and services
michaelherold
246
12k
Bash Introduction
62gerente
614
210k
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