Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Rust 製の ripgrep というツールと正規表現
Search
Yū Kobayashi
October 03, 2020
Programming
350
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Rust 製の ripgrep というツールと正規表現
Yū Kobayashi
October 03, 2020
More Decks by Yū Kobayashi
See All by Yū Kobayashi
Animator As Code As JSON As Model
kb10uy
0
430
Other Decks in Programming
See All in Programming
setup-vp GitLab対応の裏側
naokihaba
0
140
MVNOの申込からeSIM開通までをiOSアプリでつなぐ- 本人確認・MNP・通信事業者基盤をまたぐ実装
satotakeshi
0
520
AGENTS.md Is Not Enough:Build Skills, Don't Download Them
lx_t
0
130
Vue Fes Japan 2026 タイムテーブル徹底解説
448jp
1
580
re:Inventに行く前に知っておきたい現地参加のノウハウ
nokomoro3
0
290
AWSに止められる覚悟してますか?
morizo_1984
2
490
一人だけ、Kiroが静止する日
hideg
0
140
大喜利で理解するLLM as a Judge / Understanding LLM-as-a-Judge through Ogiri
rockname
0
180
動作中のプログラムの中身をリアルタイムに覗く / Realtime Debugger for CSharp with Roslyn
prota
1
1.7k
選挙速報を多くのユーザーへ 届ける Live Activities 設計
hamayokokuririn
0
190
モバイル交通系ICへのチャージ実例から考える、クロスプラットフォーム開発におけるiOS実機テスト設計とCI運用
yusuga
1
570
[Rails World 2026] Durable orchestration on Rails: from continuation to workflow
palkan
1
400
Featured
See All Featured
Evolving SEO for Evolving Search Engines
ryanjones
0
300
The Illustrated Children's Guide to Kubernetes
chrisshort
51
53k
The #1 spot is gone: here's how to win anyway
tamaranovitovic
4
1.2k
Heart Work Chapter 1 - Part 1
lfama
PRO
10
36k
Hiding What from Whom? A Critical Review of the History of Programming languages for Music
tomoyanonymous
3
1.3k
Imperfection Machines: The Place of Print at Facebook
scottboms
270
14k
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
123
22k
Reflections from 52 weeks, 52 projects
jeffersonlam
356
21k
Navigating the moral maze — ethical principles for Al-driven product design
skipperchong
2
590
Breaking role norms: Why Content Design is so much more than writing copy - Taylor Woolridge
uxyall
1
430
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
25
2.1k
コードの90%をAIが書く世界で何が待っているのか / What awaits us in a world where 90% of the code is written by AI
rkaga
63
46k
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
まとめ 秘伝の正規表現には 気をつけよう!!