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
360
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Rust 製の ripgrep というツールと正規表現
Yū Kobayashi
October 03, 2020
Transcript
8 slides
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
まとめ 秘伝の正規表現には 気をつけよう!!
More Decks by Yū Kobayashi
See All by Yū Kobayashi
Animator As Code As JSON As Model
kb10uy
0
440
Other Decks in Programming
See All in Programming
例外からRich Errorsまで Kotlinエラーハンドリングの進化を読み解く
shiita0903
0
240
선언형 햅틱 라이브러리 진동을 소개합니다
l2hyunwoo
1
330
Augmenting AI with the Power of Jakarta EE
ivargrimstad
0
420
Debian JP Projectのサーバー構成
uwabami
1
180
数行の変更でDockerビルドを最大91%高速化~GitLab CIの実行基盤を社内40リポジトリに展開するまで~
picopico
2
260
小さなアプリを作って公開するまで
onozaty
0
240
LLM 101: Exploring LLMs, Starting with Tokens.
dalinaum
0
120
社内AIエージェント「Askワンバン」における コストチューニングの取り組み
t0yohei
0
180
地方こそサーバーレス — 10年続けた、顔が見えるチームで確かな基盤を / Serverless Matters Most in Regional Areas — 10 Years of Building Reliable Foundations with Close-Knit Teams
seike460
PRO
2
510
AWS CDKを理解するために公式の定義を深掘って解説してみる / Understanding AWS CDK by Digging into Its Official Definition
akihisaikeda
3
340
Scalaの型でマルチテナントの認可を守る
nextbeatdev
0
180
느린 네트워크와 저사양 디바이스 사용자를 위한 웹뷰 로딩 시간 개선기
kmkim
1
270
Featured
See All Featured
SERP Conf. Vienna - Web Accessibility: Optimizing for Inclusivity and SEO
sarafernandez
2
1.7k
How To Stay Up To Date on Web Technology
chriscoyier
790
250k
Designing for Performance
lara
612
70k
WCS-LA-2024
lcolladotor
0
1k
The Cost Of JavaScript in 2023
addyosmani
56
10k
Heart Work Chapter 1 - Part 1
lfama
PRO
11
37k
How to Grow Your eCommerce with AI & Automation
katarinadahlin
PRO
2
360
[RailsConf 2023] Rails as a piece of cake
palkan
59
7.2k
Evolving SEO for Evolving Search Engines
ryanjones
0
370
The Mindset for Success: Future Career Progression
greggifford
PRO
0
570
The World Runs on Bad Software
bkeepers
PRO
72
12k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
38
3.1k