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
16
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
13
Snowboarding Saved My Software Career
metaljoe
0
12
Neurodiversity in Tech
metaljoe
0
55
Neurodiversity Lightning Talk
metaljoe
0
14
Tackling a Legacy Codebase with (Micro)Services
metaljoe
0
12
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
13
Other Decks in Programming
See All in Programming
「やめとこ」がなくなった — 1月にZennを始めて22本書いた AI共創開発のリアル
atani14
0
370
AWS Infrastructure as Code の新機能 2025 総まとめ 〜SA 4人による怒涛のデモ祭り〜
konokenj
10
3.3k
ふつうのRubyist、ちいさなデバイス、大きな一年 / Ordinary Rubyists, Tiny Devices, Big Year
chobishiba
1
430
コーディングルールの鮮度を保ちたい / keep-fresh-go-internal-conventions
handlename
0
190
nuget-server - あなたが必要だったNuGetサーバー
kekyo
PRO
0
230
S3ストレージクラスの「見える」「ある」「使える」は全部違う ─ 体験から見た、仕様の深淵を覗く
ya_ma23
0
380
Agent Skills Workshop - AIへの頼み方を仕組み化する
gotalab555
15
8.6k
AWS×クラウドネイティブソフトウェア設計 / AWS x Cloud-Native Software Design
nrslib
15
3k
ポーリング処理廃止によるイベント駆動アーキテクチャへの移行
seitarof
3
1k
RAGでハマりがちな"Excelの罠"を、データの構造化で突破する
harumiweb
9
2.8k
How to stabilize UI tests using XCTest
akkeylab
0
120
コードレビューをしない選択 #でぃーぷらすトウキョウ
kajitack
3
900
Featured
See All Featured
Everyday Curiosity
cassininazir
0
160
Darren the Foodie - Storyboard
khoart
PRO
3
2.8k
Making Projects Easy
brettharned
120
6.6k
Design of three-dimensional binary manipulators for pick-and-place task avoiding obstacles (IECON2024)
konakalab
0
380
Visualization
eitanlees
150
17k
First, design no harm
axbom
PRO
2
1.1k
A Guide to Academic Writing Using Generative AI - A Workshop
ks91
PRO
0
230
Mobile First: as difficult as doing things right
swwweet
225
10k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
333
22k
GraphQLの誤解/rethinking-graphql
sonatard
75
11k
What's in a price? How to price your products and services
michaelherold
247
13k
Game over? The fight for quality and originality in the time of robots
wayneb77
1
130
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