$30 off During Our Annual Pro Sale. View Details »
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
The Language of Regular Expressions. So You Thi...
Search
Riga Dev Day
March 13, 2016
0
73
The Language of Regular Expressions. So You Think You Can Speak It? by Rustam Mehmandarov
Riga Dev Day
March 13, 2016
Tweet
Share
More Decks by Riga Dev Day
See All by Riga Dev Day
Faster Java by Adding Structs (Sort Of)
rigadevday
0
160
Prepare for JDK 9! by Dalibor Topic
rigadevday
0
120
Little Important Things in Distributed Architectures by Andres Jaan Tack
rigadevday
0
130
Oracle 12c for Developers by Alex Nuijten
rigadevday
1
130
Modern Java Component Design with Spring 4.3 by Juergen Hoeller
rigadevday
0
240
Open Source and OpenJDK: Do They Deliver? by Simon Ritter
rigadevday
0
66
Google Apps Integration in Oracle Apex by Richard Martens
rigadevday
0
290
Integration Testing from the Trenches by Nicolas Fränkel
rigadevday
0
230
Distributed Systems at ok.ru by Oleg Anastasyev
rigadevday
0
79
Featured
See All Featured
Agile that works and the tools we love
rasmusluckow
331
21k
Measuring & Analyzing Core Web Vitals
bluesmoon
9
710
jQuery: Nuts, Bolts and Bling
dougneiner
65
8.3k
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
122
21k
Bootstrapping a Software Product
garrettdimon
PRO
307
120k
Heart Work Chapter 1 - Part 1
lfama
PRO
3
35k
GraphQLの誤解/rethinking-graphql
sonatard
73
11k
Noah Learner - AI + Me: how we built a GSC Bulk Export data pipeline
techseoconnect
PRO
0
73
The B2B funnel & how to create a winning content strategy
katarinadahlin
PRO
0
190
Become a Pro
speakerdeck
PRO
31
5.7k
Ten Tips & Tricks for a 🌱 transition
stuffmc
0
34
Hiding What from Whom? A Critical Review of the History of Programming languages for Music
tomoyanonymous
0
300
Transcript
The Language of Regular Expressions. So You Think You Can
Speak It? Rustam Mehmandarov Riga Dev Day
The Vision http://xkcd.com/208/
…but regex ain’t one! Oh, wait! http://xkcd.com/1171/
The Reality
None
(([0-9]{4})-([0-9]{2})-([0-9]{2})).*\sINFO\s(.*)
Log4j Log File
.*(INFO|WARN).*
.*(INFO|WARN).*
(([0-9]{4})-([0-9]{2})-([0-9]{2})).*ERROR(.*)
(([0-9]{4})-([0-9]{2})-([0-9]{2})).*ERROR(.*)
^.*192\.168\.0\.6[^9](.*)$
^.*192.168.0.6[^9](.*)
^.*192\.168\.0\.6[^9](.*)$
^.*192\.168\.0\.6[0-9]+[^9](.*)$
flavou?r
Recap: Quantifiers * + ? {num} {num, num}
Recap: Grouping .*(INFO|WARN)(.*) .*(INFO|WARN)(?:.*)
(WA) 2014-09-09 WAR FILE WARN [com.example.logging.MyLog]
(?=WARN)WA 2014-09-09 WAR FILE WARN [com.example.logging.MyLog]
(?=WARN)WA
Recap: Lookaround (?=foo) -> Lookahead (?<=foo) -> Lookbehind (?!foo) ->
Negative Lookahead (?<!foo) -> Negative Lookbehind
Lookahead: Example
The list
Backreferences
Backreferences (contd.)
Text: OSDC is awesome! HTML: OSDC is <em>awesome</em>! Regex: <.+>
Result:
Text: OSDC is awesome! HTML: OSDC is <em>awesome</em>! Regex: <.+?>
Result:
None
http://stackoverflow.com/questions/1732348/ regex-match-open-tags-except-xhtml-self- contained-tags
Quantifiers Revisited Greedy: *, +, ?, {num, num} Non-greedy: *?,
+?, ??, {num, num}?
Final Recap • Know your data! – Think what you
should match – Think what you should not match • Know your flavor • Know your engine (DFA, NFA) – Backtracking • Greediness • Non-capturing parenthesis • Anchors
MOAR! EXAMPLES!
Matching an IP - 1 Idea 1: ^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$ Result:
Matching an IP - 2 Idea 2: ^\d\d\d\.\d\d\d\.\d\d\d\.\d\d\d$ Result:
Matching an IP - 3 Idea 3: ^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$ Result:
Matching an IP - 4 Idea 4: ^ ([01]?\d\d?|2[0-4]\d|25[0-5])\. ([01]?\d\d?|2[0-4]\d|25[0-5])\.
([01]?\d\d?|2[0-4]\d|25[0-5])\. ([01]?\d\d?|2[0-4]\d|25[0-5]) $ Result:
Your New Reality! http://xkcd.com/208/
Thank you! rmehmandarov
[email protected]
None