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
Rust 製の ripgrep というツールと正規表現
Search
Yū Kobayashi
October 03, 2020
Programming
0
230
Rust 製の ripgrep というツールと正規表現
Yū Kobayashi
October 03, 2020
Tweet
Share
More Decks by Yū Kobayashi
See All by Yū Kobayashi
Animator As Code As JSON As Model
kb10uy
0
210
Other Decks in Programming
See All in Programming
[After Kotlin Fest 2024 LT Night @ Sansan] もっともっとKotlinを好きになる!K2 Compiler Pluginで遊んでみよう!
kitakkun
2
260
Xcode 16のPreviewModifierと@Previewableを活用した効率的なプレビュー方法の考察
ojun9
2
160
Play Billing Library 7.0.0 変更点まとめ@potatotips#88
kako351
0
160
Google's Recipe for Scaling (Web) Security – LocoMocoSec 2024
lweichselbaum
0
170
CSC307 Lecture 09
javiergs
PRO
1
500
The rollercoaster of releasing an Android, iOS, and macOS app with Kotlin Multiplatform | droidcon Berlin
prof18
0
110
CSC307 Lecture 10
javiergs
PRO
0
310
TiDB Serverless ~理想のServerless DBを考える~
soso_15315
1
160
今こそ始める、CDKコンストラクトライブラリ開発 ― 入門から実践まで
tmokmss
1
930
スクラムマスターって孤独じゃないですか?
yoshitaroyoyo
1
140
さきがけから振り返るアーキテクチャ刷新 / Reflecting on the Architectural Renewal from the Vanguard
nrslib
2
780
APIのない大学ログインWebサービスをWKWebViewとJavaScriptでアプリ化した話
akidon0000
1
330
Featured
See All Featured
A Modern Web Designer's Workflow
chriscoyier
689
190k
jQuery: Nuts, Bolts and Bling
dougneiner
61
7.4k
For a Future-Friendly Web
brad_frost
173
9.2k
Practical Orchestrator
shlominoach
185
10k
Building Better People: How to give real-time feedback that sticks.
wjessup
357
18k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
662
120k
GraphQLとの向き合い方2022年版
quramy
36
13k
4 Signs Your Business is Dying
shpigford
178
21k
Principles of Awesome APIs and How to Build Them.
keavy
124
16k
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
24
1.8k
Reflections from 52 weeks, 52 projects
jeffersonlam
346
19k
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
36
9.1k
Transcript
Rust 製の ripgrep という ツールと正規表現 kb10uy / 日下夏稀
自己紹介 • kb10uy (ケイビージュウユーワイ) • おととい内定式に出てきた • ルービックキューブ 40 秒切れるようになっ
てきた • https://kb10uy.org
Ripgrep というツール • grep のすごいやつ • Rust で書かれているので速い • 最初からディレクトリの再帰的検索をサポート
• .gitignore とかを認識して除外してくれる • 速い!! • grep に限らず様々なツールで正規表現が使われている • そのお話をちょっとします
正規表現の実装 • PCRE2 などの正規表現エンジンは従来型NFAと称されている • (数学的には)正規ではない表現も使える • 例: /((.+)¥2){2}/ ……
“つつうらうら”、”かんかんがくがく”など • 一方、POSIX コマンドのデフォルトや ripgrep のデフォルトの 正規表現は DFA で実装されている • 「記憶」が必要な表現は基本的に無理
じゃあ NFA だけでよくない? • そう思うじゃん?でもね…… • 実行時間も消費メモリ量も増える • 特に実行時間が致命的 •
有名な例として /X(.+)+X/ を =XX================= にマッ チさせるとバックトラックが爆発して終わらない
DFA はエコ • DFA の正規表現は計算量が線形 • バックトラック用に記憶しておく必要がないのでメモリにもや さしい • Rust
の regex crate や Golang の regex はスケールした際の最 悪ケースを考慮している(と言われている) • そもそもバックトラックそんな使ってなくない? • 個人差があります • 僕は (*SKIP) とか (*PRUNE) とか好きだよ
SKK の辞書から色々な単語を抽出しよう • 昨日ブログに書いた話 • 実演 • https://kb10uy.hateblo.jp/entry/2020/10/02/131621
まとめ 秘伝の正規表現には 気をつけよう!!