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
200
Other Decks in Programming
See All in Programming
Revisiting the Hotwire Landscape after Turbo 8 @ RailsConf 2024, Detroit
marcoroth
0
260
Git Rebase
bkuhlmann
11
1.6k
dbtのドメイン分割による データ基盤の改善とDigdagとの連携
sakama
0
480
Fast JSX: Don't clone props object #28768
yossydev
1
220
Azure OpenAI Serviceのプロンプトエンジニアリング入門
tomokusaba
3
930
Fragment Composition of GraphQL
quramy
13
1.6k
Elm 0.19.0 Changes
bkuhlmann
0
510
『Railsオワコン』と言われる時代に、なぜブルーモ証券はRailsを選ぶのか
free_world21
2
400
Site Reliability Engineering for GMO
pyama86
9
1.1k
Ruby Function Composition
bkuhlmann
1
340
Milestoner
bkuhlmann
1
420
Exploring the Implementation of “t.Run”, “t.Parallel”, and “t.Cleanup”
akarin
1
140
Featured
See All Featured
Faster Mobile Websites
deanohume
300
30k
How GitHub (no longer) Works
holman
305
140k
The Invisible Customer
myddelton
114
12k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
228
16k
Navigating Team Friction
lara
179
13k
No one is an island. Learnings from fostering a developers community.
thoeni
16
2.1k
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
14
8.4k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
126
32k
Web Components: a chance to create the future
zenorocha
306
41k
Happy Clients
brianwarren
92
6.4k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
226
51k
Art, The Web, and Tiny UX
lynnandtonic
290
19k
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
まとめ 秘伝の正規表現には 気をつけよう!!