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
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
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
15年続くIoTサービスのSREエンジニアが挑む分散トレーシング導入
melonps
2
230
今から始めるClaude Code超入門
448jp
8
9.1k
Lambda のコードストレージ容量に気をつけましょう
tattwan718
0
150
AIエージェント、”どう作るか”で差は出るか? / AI Agents: Does the "How" Make a Difference?
rkaga
4
2k
CSC307 Lecture 10
javiergs
PRO
1
660
AI Schema Enrichment for your Oracle AI Database
thatjeffsmith
0
330
Amazon Bedrockを活用したRAGの品質管理パイプライン構築
tosuri13
5
800
コントリビューターによるDenoのすゝめ / Deno Recommendations by a Contributor
petamoriken
0
210
Automatic Grammar Agreementと Markdown Extended Attributes について
kishikawakatsumi
0
200
AIフル活用時代だからこそ学んでおきたい働き方の心得
shinoyu
0
140
Package Management Learnings from Homebrew
mikemcquaid
0
230
責任感のあるCloudWatchアラームを設計しよう
akihisaikeda
3
180
Featured
See All Featured
[SF Ruby Conf 2025] Rails X
palkan
1
760
Taking LLMs out of the black box: A practical guide to human-in-the-loop distillation
inesmontani
PRO
3
2k
Building Flexible Design Systems
yeseniaperezcruz
330
40k
We Are The Robots
honzajavorek
0
170
How To Stay Up To Date on Web Technology
chriscoyier
791
250k
Mind Mapping
helmedeiros
PRO
0
90
Efficient Content Optimization with Google Search Console & Apps Script
katarinadahlin
PRO
1
330
jQuery: Nuts, Bolts and Bling
dougneiner
65
8.4k
<Decoding/> the Language of Devs - We Love SEO 2024
nikkihalliwell
1
130
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
287
14k
Stewardship and Sustainability of Urban and Community Forests
pwiseman
0
110
The agentic SEO stack - context over prompts
schlessera
0
650
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
まとめ 秘伝の正規表現には 気をつけよう!!