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
3 Effective Rules for Using Signals in Angular
manfredsteyer
PRO
1
100
Amazon Qを使ってIaCを触ろう!
maruto
0
410
[Do iOS '24] Ship your app on a Friday...and enjoy your weekend!
polpielladev
0
110
Remix on Hono on Cloudflare Workers
yusukebe
1
300
見せてあげますよ、「本物のLaravel批判」ってやつを。
77web
7
7.8k
OSSで起業してもうすぐ10年 / Open Source Conference 2024 Shimane
furukawayasuto
0
110
距離関数を極める! / SESSIONS 2024
gam0022
0
290
Hotwire or React? ~アフタートーク・本編に含めなかった話~ / Hotwire or React? after talk
harunatsujita
1
120
ふかぼれ!CSSセレクターモジュール / Fukabore! CSS Selectors Module
petamoriken
0
150
レガシーシステムにどう立ち向かうか 複雑さと理想と現実/vs-legacy
suzukihoge
14
2.2k
subpath importsで始めるモック生活
10tera
0
310
Generative AI Use Cases JP (略称:GenU)奮闘記
hideg
1
300
Featured
See All Featured
VelocityConf: Rendering Performance Case Studies
addyosmani
325
24k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
131
33k
Fontdeck: Realign not Redesign
paulrobertlloyd
82
5.2k
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
29
2.3k
Facilitating Awesome Meetings
lara
50
6.1k
Fantastic passwords and where to find them - at NoRuKo
philnash
50
2.9k
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
PRO
10
720
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
159
15k
What's in a price? How to price your products and services
michaelherold
243
12k
The Cult of Friendly URLs
andyhume
78
6k
Automating Front-end Workflow
addyosmani
1366
200k
Intergalactic Javascript Robots from Outer Space
tanoku
269
27k
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νϟϯωϧʹͯ