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
320
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
380
Other Decks in Programming
See All in Programming
登壇資料を作る時に意識していること #登壇資料_findy
konifar
4
1.7k
The Past, Present, and Future of Enterprise Java
ivargrimstad
0
620
OCaml 5でモダンな並列プログラミングを Enjoyしよう!
haochenx
0
150
要求定義・仕様記述・設計・検証の手引き - 理論から学ぶ明確で統一された成果物定義
orgachem
PRO
1
240
コマンドとリード間の連携に対する脅威分析フレームワーク
pandayumi
1
470
CSC307 Lecture 06
javiergs
PRO
0
690
カスタマーサクセス業務を変革したヘルススコアの実現と学び
_hummer0724
0
740
プロダクトオーナーから見たSOC2 _SOC2ゆるミートアップ#2
kekekenta
0
230
Lambda のコードストレージ容量に気をつけましょう
tattwan718
0
150
AIエージェント、”どう作るか”で差は出るか? / AI Agents: Does the "How" Make a Difference?
rkaga
4
2k
Data-Centric Kaggle
isax1015
2
780
IFSによる形状設計/デモシーンの魅力 @ 慶應大学SFC
gam0022
1
310
Featured
See All Featured
The Curse of the Amulet
leimatthew05
1
8.7k
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
659
61k
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
254
22k
The Invisible Side of Design
smashingmag
302
51k
Visual Storytelling: How to be a Superhuman Communicator
reverentgeek
2
440
Future Trends and Review - Lecture 12 - Web Technologies (1019888BNR)
signer
PRO
0
3.2k
How to Talk to Developers About Accessibility
jct
2
140
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
162
16k
A Modern Web Designer's Workflow
chriscoyier
698
190k
How People are Using Generative and Agentic AI to Supercharge Their Products, Projects, Services and Value Streams Today
helenjbeal
1
130
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
333
22k
We Have a Design System, Now What?
morganepeng
54
8k
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
まとめ 秘伝の正規表現には 気をつけよう!!