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
正規表現改善報告する回 / Regexp memoization progress report
Search
TSUYUSATO Kitsune
August 19, 2023
Programming
2
540
正規表現改善報告する回 / Regexp memoization progress report
RubyKaigi 2023 follow up(
https://rhc.connpass.com/event/288535/
) での発表資料です。
TSUYUSATO Kitsune
August 19, 2023
Tweet
Share
More Decks by TSUYUSATO Kitsune
See All by TSUYUSATO Kitsune
YAPC::Japan::Online 2022で発表して WEB+DB PRESSに記事を寄稿した話
makenowjust
0
15
Regular Expressions, REXML, Automata Learning
makenowjust
0
260
オートマトン学習しろ / Do automata learning
makenowjust
3
170
#kaigieffect LT 2024 - rexml-css_selector: A REXML extension for supporting CSS selector
makenowjust
1
320
RubyKaigi 2024 - Make Your Own Regex Engine!
makenowjust
1
1.4k
Make Regexp#match much faster
makenowjust
1
2.6k
ReDoS 検出の最先端 recheck の紹介 / State of the Art of ReDoS Detection
makenowjust
9
3.4k
ReDoS 検出プログラム recheck の開発 / recheck: ReDoS check program
makenowjust
0
120
Integrated Shrinking による 高階関数の自動生成 / PRO-2020-4 Generating Higher-Order Functions by Integrated Shrinking
makenowjust
0
130
Other Decks in Programming
See All in Programming
Hotwire or React? ~アフタートーク・本編に含めなかった話~ / Hotwire or React? after talk
harunatsujita
1
120
距離関数を極める! / SESSIONS 2024
gam0022
0
280
役立つログに取り組もう
irof
28
9.6k
Compose 1.7のTextFieldはPOBox Plusで日本語変換できない
tomoya0x00
0
190
Why Jakarta EE Matters to Spring - and Vice Versa
ivargrimstad
0
1.1k
Nurturing OpenJDK distribution: Eclipse Temurin Success History and plan
ivargrimstad
0
890
Tauriでネイティブアプリを作りたい
tsucchinoko
0
370
受け取る人から提供する人になるということ
little_rubyist
0
230
Enabling DevOps and Team Topologies Through Architecture: Architecting for Fast Flow
cer
PRO
0
320
ローコードSaaSのUXを向上させるためのTypeScript
taro28
1
610
Jakarta EE meets AI
ivargrimstad
0
600
OnlineTestConf: Test Automation Friend or Foe
maaretp
0
110
Featured
See All Featured
Designing the Hi-DPI Web
ddemaree
280
34k
Git: the NoSQL Database
bkeepers
PRO
427
64k
Writing Fast Ruby
sferik
627
61k
Code Review Best Practice
trishagee
64
17k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
665
120k
Optimising Largest Contentful Paint
csswizardry
33
2.9k
What's in a price? How to price your products and services
michaelherold
243
12k
A Tale of Four Properties
chriscoyier
156
23k
It's Worth the Effort
3n
183
27k
Rails Girls Zürich Keynote
gr2m
94
13k
Music & Morning Musume
bryan
46
6.2k
How to train your dragon (web standard)
notwaldorf
88
5.7k
Transcript
౻࿘େ !NBLF@OPX@KVTU !3VCZ,BJHJGPMMPXVQ ਖ਼نදݱվળใࠂ͢Δճ
લճͷ͋Β͢͡ IUUQTSVCZLBJHJPSHQSFTFOUBUJPOTNBLFOPXKVTUIUNMEBZ
લճͷ͋Β͢͡ ਖ਼نදݱϚονϯάΛΊͬͪΌͨ͘͠
લճͷ͋Β͢͡ ͔͠͠ɺਖ਼نදݱ͕͘ͳΔͨΊʹ੍͍͔͕ͭ͘
લճͷ͋Β͢͡ ੍ϑϦʔͳੈքΛΊͯ͟͠ ό Ϧ Ξ
੍#FGPSF w ͜ΕΒͷػೳΛ͏ͱɺਖ਼نදݱϚονϯά͕࠷దԽ͞Εͳ͍ ʮઌಡΈɾޙಡΈʯ(?=foo) (?<=bar)ʮΞτϛοΫάϧʔϓʯ(?>foo) ʮ݅ذʯ(?(<x>)yes|no)ʮඇแؚԋࢉࢠʯ(?~foo) ʮޙํࢀরʯ(foo)\1
ʮ෦ࣜͷݺͼग़͠ʯ(?<x>foo)\g<x> w ͦͷଞɺಾͷ੍ͨͪ ճࢦఆͷ܁Γฦ͕͠ωετͰ͖ͳ͍(fo{1,23}){42} ۭจࣈྻʹϚον͢Δ͔͠Εͳ͍܁Γฦ͕͠ωετͰ͖ͳ͍
w ͜ΕΒͷػೳΛ͏ͱɺਖ਼نදݱϚονϯά͕࠷దԽ͞Εͳ͍ ʮઌಡΈɾޙಡΈʯ(?=foo) (?<=bar)ʮΞτϛοΫάϧʔϓʯ(?>foo) ʮ݅ذʯ(?(<x>)yes|no)ʮඇแؚԋࢉࢠʯ(?~foo) ʮޙํࢀরʯ(foo)\1 ʮ෦ࣜͷݺͼग़͠ʯ(?<x>foo)\g<x>
w ͦͷଞɺಾͷ੍ͨͪ ճࢦఆͷ܁Γฦ͕͠ωετͰ͖ͳ͍(fo{1,23}){42} ۭจࣈྻʹϚον͢Δ͔͠Εͳ͍܁Γฦ͕͠ωετͰ͖ͳ͍ ੍"GUFS
w ͜ΕΒͷػೳΛ͏ͱɺਖ਼نදݱϚονϯά͕࠷దԽ͞Εͳ͍ ʮઌಡΈɾޙಡΈʯ(?=foo) (?<=bar)ʮΞτϛοΫάϧʔϓʯ(?>foo) ʮ݅ذʯ(?(<x>)yes|no)ʮඇแؚԋࢉࢠʯ(?~foo) ʮޙํࢀরʯ(foo)\1 ʮ෦ࣜͷݺͼग़͠ʯ(?<x>foo)\g<x>
w ͦͷଞɺಾͷ੍ͨͪ ճࢦఆͷ܁Γฦ͕͠ωετͰ͖ͳ͍(fo{1,23}){42} ۭจࣈྻʹϚον͢Δ͔͠Εͳ͍܁Γฦ͕͠ωετͰ͖ͳ͍ ੍"GUFS ඍົʁ
w ͜ΕΒͷػೳΛ͏ͱɺਖ਼نදݱϚονϯά͕࠷దԽ͞Εͳ͍ ʮઌಡΈɾޙಡΈʯ(?=foo) (?<=bar)ʮΞτϛοΫάϧʔϓʯ(?>foo) ʮ݅ذʯ(?(<x>)yes|no)ʮඇแؚԋࢉࢠʯ(?~foo) ʮޙํࢀরʯ(foo)\1 ʮ෦ࣜͷݺͼग़͠ʯ(?<x>foo)\g<x>
w ͦͷଞɺಾͷ੍ͨͪ ճࢦఆͷ܁Γฦ͕͠ωετͰ͖ͳ͍(fo{1,23}){42} ۭจࣈྻʹϚον͢Δ͔͠Εͳ͍܁Γฦ͕͠ωετͰ͖ͳ͍ ੍"GUFS ཧతʹແཧ ͋·ΓΘΕͯͳ͍
w ͜ΕΒͷػೳΛ͏ͱɺਖ਼نදݱϚονϯά͕࠷దԽ͞Εͳ͍ ʮઌಡΈɾޙಡΈʯ(?=foo) (?<=bar)ʮΞτϛοΫάϧʔϓʯ(?>foo) ʮ݅ذʯ(?(<x>)yes|no)ʮඇแؚԋࢉࢠʯ(?~foo) ʮޙํࢀরʯ(foo)\1 ʮ෦ࣜͷݺͼग़͠ʯ(?<x>foo)\g<x>
w ͦͷଞɺಾͷ੍ͨͪ ճࢦఆͷ܁Γฦ͕͠ωετͰ͖ͳ͍(fo{1,23}){42} ۭจࣈྻʹϚον͢Δ͔͠Εͳ͍܁Γฦ͕͠ωετͰ͖ͳ͍ ੍"GUFS ཧతʹແཧ ͋·ΓΘΕͯͳ͍ ͦΜͳʹ ѱ͘ͳ͍ʁ
͜Ε·ͰͷϝϞԽ w ී௨ͷਖ਼نදݱͷ߹ɺ ʮ͋Δঢ়ଶʹ͋ΔҐஔ͔ΒͷϚονͰࣦഊͨ͠ʯͱ͍͏ใΛه͢Ε0, w ϝϞԽςʔϒϧͷܕ memo: (State,
Int) -> (NoMemo | Failure) w ઌಡΈɾޙಡΈ͕͋Δ߹ɺΞτϛοΫάϧʔϓ͕͋Δ߹ʁ
ઌಡΈɾޙಡΈͷϝϞԽ w ઌಡΈɾޙಡΈ෦Ϛονϯάࣦഊ͍ͯ͠ͳͯ͘ɺ ʮ͋Δঢ়ଶɾ͋ΔҐஔʯʹ͏Ұ౸ୡ͢ΔՄೳੑ͕͋Δ ྫ/a*?(?=a*)z/ w ʮઌಡΈɾޙಡΈ෦ͷϚονϯάʹޭͨ͠ʯͱ͍͏ใΛ
ϝϞԽςʔϒϧʹه͢Δඞཁ͕͋Δ w ϝϞԽςʔϒϧͷܕ memo: (State, Int) -> (NoMemo | Success | Failure)
ΞτϛοΫά ϧʔϓͷϝϞԽ w ΞτϛοΫά ϧʔϓͷ߹ɺ ΞτϛοΫά ϧʔϓͷதͰͷࣦഊͱɺ֎ଆͰͷࣦഊΛ۠ผ͠ͳ͚Ε͍͚ͳ͍ ֎ଆͰࣦഊͨ͠߹ɺΞτϛοΫά ϧʔϓͷதͷόοΫτϥοΫ
লུ͠ͳ͚Ε͍͚ͳ͍ w ϝϞԽςʔϒϧͷܕ memo: (State, Int) -> (NoMemo | Success | AtomicFailure | Failure)
࣮ͷमਖ਼ w ࣮ࡍͷϝϞԽςʔϒϧCJUྻͳͷͰɺ ઌಡΈɾޙಡΈɾΞτϛοΫά ϧʔϓͷঢ়ଶʹରͯ͠ CJUͬͯϝϞԽ͢ΔΑ͏ʹͨ͠ w ͜Ε·Ͱʮ͋Δঢ়ଶʹ͋ΔҐஔͰ౸ୡͨ͠ʯͱ͍͏ใΛه͍͕ͯͨ͠ɺ
ʮ͋Δঢ়ଶʹ͋ΔҐஔ͔ΒͷϚονʹࣦഊͨ͠ʯͱ͍͏ใʹ͢ΔͨΊɺ όοΫτϥοΫதʹϝϞԽςʔϒϧΛߋ৽͢ΔΑ͏ʹͨ͠ IUUQTHJUIVCDPNSVCZSVCZQVMM
ݱࡏͷ੍ w ͜ΕΒͷػೳΛ͏ͱɺਖ਼نදݱϚονϯά͕࠷దԽ͞Εͳ͍ ʮ݅ذʯ(?(<x>)yes|no)ʮඇแؚԋࢉࢠʯ(?~foo) ʮޙํࢀরʯ(foo)\1 ʮ෦ࣜͷݺͼग़͠ʯ(?<x>foo)\g<x> w ͦͷଞɺಾͷ੍ͨͪ
ճࢦఆͷ܁Γฦ͕͠ωετͰ͖ͳ͍(fo{1,23}){42} ઌಡΈɾޙಡΈͱΞτϛοΫά ϧʔϓ͕ωετͰ͖ͳ͍ ઌಡΈɾޙಡΈɾΞτϛοΫά ϧʔϓͷதͰΩϟϓνϟ͑ͳ͍
ΏΔ΅ w ੍ʹ͔͔Βͳ͍͔Ͳ͏͔ΛRegexp.linear_time?ͰνΣοΫͰ͖·͢ w ͜ΕΛͬͯɺϓϩάϥϜதͷਖ਼نදݱ੍͕ʹ͔͔Βͳ͍͔νΣοΫ͢Δ 3VCPDPQϓϥάΠϯΛ࡞ͬͯɺϝϯςφϯεͯ͘͠ΕΔਓΛืू͍ͯ͠·͢ SVCZKQ4MBDLͷSFHFYQνϟϯωϧʹͯ