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
270
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
250
Other Decks in Programming
See All in Programming
複数のAWSアカウントから横断で 利用する Lambda Authorizer の作り方
tc3jp
0
130
iOSでQRコード生成奮闘記
ktcryomm
2
150
気がついたら子供が社会人になって 自分と同じモバイルアプリエンジニアになった件 / Parent-Child Engineers
koishi
0
130
CSS Linter による Baseline サポートの仕組み
ryo_manba
1
170
Djangoにおける複数ユーザー種別認証の設計アプローチ@DjangoCongress JP 2025
delhi09
PRO
4
520
自力でTTSモデルを作った話
zgock999
0
140
たのしいSocketのしくみ / Socket Under a Microscope
coe401_
8
1.5k
LINE messaging APIを使ってGoogleカレンダーと連携した予約ツールを作ってみた
takumakoike
0
150
Google Cloudとo11yで実現するアプリケーション開発者主体のDB改善
nnaka2992
1
160
フロントエンドオブザーバビリティ on Google Cloud
yunosukey
0
110
Better Code Design in PHP
afilina
0
190
はじめての Go * WASM * OCR
sgash708
1
130
Featured
See All Featured
Thoughts on Productivity
jonyablonski
69
4.5k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
27
1.6k
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
4
450
Faster Mobile Websites
deanohume
306
31k
The Power of CSS Pseudo Elements
geoffreycrofte
75
5.5k
Agile that works and the tools we love
rasmusluckow
328
21k
Building an army of robots
kneath
303
45k
KATA
mclloyd
29
14k
Building a Scalable Design System with Sketch
lauravandoore
462
33k
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
21
2.5k
Why You Should Never Use an ORM
jnunemaker
PRO
55
9.2k
Fashionably flexible responsive web design (full day workshop)
malarkey
406
66k
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
まとめ 秘伝の正規表現には 気をつけよう!!