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
The 1960s elegance behind Go's regexp
Search
Jalem Raj Rohit
March 19, 2017
Programming
1
160
The 1960s elegance behind Go's regexp
The presentation is given at FOSS Asia Summit 2017
Jalem Raj Rohit
March 19, 2017
Tweet
Share
More Decks by Jalem Raj Rohit
See All by Jalem Raj Rohit
Training and leveraging graph embeddings at scale
dawny33
2
81
Lessons learned from building serverless, distributed architecture
dawny33
1
110
Regression Analysis: The good, the bad and untold
dawny33
2
380
Understanding Serverless Architectures
dawny33
2
1.4k
Other Decks in Programming
See All in Programming
Nealle_Autify_LT_Slide202403
nealle
0
160
Netty Chicago Java User Group 2024-04-17
sullis
0
170
TYPO3 v13 – The road to LTS: What's new and new APIs
luisasofie_xoxo
0
190
try! Swift Tokyo 初参加報告LT
hinakko2
0
220
エンターテイメント業界で利用されるAWS
demuyan
0
210
0→1と1→10の狭間で Javaという技術選定を振り返る/Reflecting on the Decision to Choose Java Between Scaling from 0 to 1 and 1 to 10
jaguar_imo
2
380
Random\Randomizer クラスで日常のあれこれを解決しよう! / Random\Randomizer class solves familiar trouble
cocoeyes02
0
190
Amazon SQSコンシューマー疎結合への旅 - 出張! #DevelopersIO IT技術ブログの中の人が語る勉強会 #3
quiver
0
230
OpenAPIを中心に考えるAPI開発入門 / Introduction to API Development with a Focus on OpenAPI
seike460
PRO
2
160
使ってみよう Azure AI Document Intelligence
kosmosebi
2
280
GraphQLサーバの構成要素を整理する #ハッカー鮨 #tsukijigraphql / graphql server technology selection
izumin5210
4
820
サイコロで理解する統計的仮説検定の考え方
tatamiya
4
890
Featured
See All Featured
Build The Right Thing And Hit Your Dates
maggiecrowley
24
2k
Building Effective Engineering Teams - LeadDev
addyosmani
28
1.8k
VelocityConf: Rendering Performance Case Studies
addyosmani
320
23k
Automating Front-end Workflow
addyosmani
1356
200k
A Tale of Four Properties
chriscoyier
151
22k
The Art of Programming - Codeland 2020
erikaheidi
42
12k
GraphQLとの向き合い方2022年版
quramy
32
12k
Statistics for Hackers
jakevdp
789
220k
Writing Fast Ruby
sferik
621
60k
Agile that works and the tools we love
rasmusluckow
325
20k
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
21
1.6k
Mobile First: as difficult as doing things right
swwweet
216
8.6k
Transcript
The 1960s elegance behind Go’s regexp 19 MarchFOSS Asia ‘17
Jalem Raj Rohit
What this talk is about? About the two approaches to
regex matching. - One used in almost all standard regex interpreters, like Python, Perl, etc - The other one used in some implementations like, awk, grep, sed, etc And Go, of course
What exactly are Regular Expressions? - It’s a style of
describing character strings - If a string successfully describes a regex, then it is called a match
Examples: Let’s say e1 matches “s” and e2 matches “t”:
➔ Alternation If e1 | e2 ⇒ s or it ➔ Concatenation e1 e2 ⇒ st. ➔ e1* 0 or more s ➔ e1+ 1 or more s
Perl vs Golang time comparison for matching a?a?a?aaa with respect
to the string length
Aaaand welcome to: The world of super awesome Computer Science
! and Super awesome algorithms !
Meet Finite Automata - It’s also known as State Machines
- ← This one is a Deterministic Finite Automata (or a DFA)
Also, meet NFA - NFA stands for Nondeterministic Finite Automata
- Example on the left - It has multiple legit choices in state S2 Which one to choose? :( - Also, the machine can’t peek ahead
Converting Regexes to NFAs - This would be the basic
unit of the NFA - Concatenation be like: - Aaaand alternation
Perl’s algorithm at work - Also, called the backtracking approach
- Time complexity grows exponentially for pathological regex matches, as the string size grows. - Literally, out of the window
Can we make this better?
Thompson’s algorithm at work - Guesses both options simultaneously -
Allows the machine to be in multiple states at the same time - Linear time complexity. Yayyy !!!
Again, comparison of the algorithms
Again ….
Special Shoutout to GopherData - An attempt to bring together
Go’s and gophers’ efforts in Data Science and Analytics - Github: https://github.com/gopherdata - Twitter: https://twitter.com/GopherDataIO
THANK YOU - Github: Dawny33 - Twitter: @data__wizard (<-- 2
_’s there) - Facebook: rajrohit.33