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
正規表現エンジンを自作した話
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
北村
August 23, 2025
Technology
33
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
正規表現エンジンを自作した話
北村
August 23, 2025
More Decks by 北村
See All by 北村
LLMの出力を構造化したい
shu_kita
0
350
Azure Container Appsを使ってみた
shu_kita
0
270
ギャルのパンティおくれ
shu_kita
1
260
LSMツリー
shu_kita
0
27
掲示板への不適切な投稿を防ぐ
shu_kita
0
270
Other Decks in Technology
See All in Technology
Kotlin 開発のツラミを爆破した話! / Explode the difficulty of Kotlin dev!
eller86
0
120
5分でわかる Amazon Connect_20260608
hwangbyeonghun
0
150
作る力から、見極める力へ — AI時代に広がるエンジニアの価値と役割
rince
0
380
Microsoft のサポートとフィードバック総まとめ
murachiakira
PRO
0
130
「ビジネスがわかるエンジニア」とは何か?
ryooob
0
420
#エンジニアBooks 30分でわかる 「技術記事を書く技術」 / engineer-books 2026-06-30
jnchito
1
150
4人目のSREはAgent
tanimuyk
0
310
WebGIS AI Agentの紹介
_shimizu
0
600
はてなのサービス基盤を支える Kubernetes《足腰》
masayoshimaezawa
0
310
なぜ人は自分のプロジェクトを 「なんちゃってアジャイル」と 自嘲するのか
kozotaira
0
200
AWS Summit の片隅で、体育座りしながらコミュニティがにぎわう理由を考えた
k_adachi_01
2
300
From Prompt Engineering to Loop Engineering
shibuiwilliam
1
300
Featured
See All Featured
Why Mistakes Are the Best Teachers: Turning Failure into a Pathway for Growth
auna
0
170
Gemini Prompt Engineering: Practical Techniques for Tangible AI Outcomes
mfonobong
2
450
Redefining SEO in the New Era of Traffic Generation
szymonslowik
1
350
Kristin Tynski - Automating Marketing Tasks With AI
techseoconnect
PRO
0
280
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
35
3.5k
SEO Brein meetup: CTRL+C is not how to scale international SEO
lindahogenes
1
2.7k
Being A Developer After 40
akosma
91
590k
The Straight Up "How To Draw Better" Workshop
denniskardys
239
140k
The SEO identity crisis: Don't let AI make you average
varn
0
510
Keith and Marios Guide to Fast Websites
keithpitt
413
23k
Reality Check: Gamification 10 Years Later
codingconduct
0
2.2k
Money Talks: Using Revenue to Get Sh*t Done
nikkihalliwell
0
260
Transcript
VM型正規表現エンジンを自作した話 ~正規表現マッチングの仕組みをしろう~ shu-kitamura
自己紹介 • 1998年生まれ(26歳) • 大阪出身、4年前に札幌転勤 • テニス、フットサル • 今日は正規表現エンジンの仕組みについて話します •
LTは初めてです。お手柔らかに お手やわらカニ
1. 正規表現エンジンとは 正規表現のマッチングを行う処理系のこと。 主要な正規表現エンジンの実装 • DFA型 : 決定性有限オートマトン(DFA)を用いてマッチングを行う • VM型
: 正規表現用の命令セットを用いてマッチングを行う VMは Virtual Machine の略 パターン 例 : a(b|c)d 文字列 正規表現 エンジン マッチング結果 ※正規表現の構文の説明はしません
1. 正規表現エンジンとは 正規表現のマッチングを行う処理系のこと。 主要な正規表現エンジンの実装 • DFA型 : 決定性有限オートマトン(DFA)を用いてマッチングを行う • VM型
: 正規表現用の命令セットを用いてマッチングを行う VMは Virtual Machine の略 パターン 例 : a(b|c)d 文字列 正規表現 エンジン マッチング結果 ※正規表現の構文の説明はしません 今日はこっちの説明をします
2. マッチング処理の流れ VM型正規表現エンジンのマッチング処理の流れ ① パターンを解析して AST(抽象構文木)に変換 ② AST を命令に変換 ③
VM が命令を解釈して、文字列とマッチング パターン 例 : a(b|c)d 文字列 マッチング結果 VM型正規表現エンジン AST 命令 VM ① ② ③
2. マッチング処理の流れ ① パターンを解析して AST(抽象構文木) に変換する AST a b c
d or concat 解析 a(b|c)d b|c a d concat or a d concat b c 変換 パターン
2. マッチング処理の流れ ② AST を命令に変換 正規表現エンジンが使用する命令セット 命令 説明 char 文字の比較を行う
split 処理を分岐させる jump 指定した命令に移動する match マッチの成功を表す AST a b c d or concat 命令 0: char a 1 : split 2, 4 2: char b 3: jump 5 4: char c 5: char d 6: match 変換 仕組みを知る上では 「変換しているんだなぁ」という 理解でOKです。
③VMが命令を解釈して、文字列とマッチング 2. マッチング処理の流れ VM 命令 0: char a 1 :
split 2, 4 2: char b 3: jump 5 4: char c 5: char d 6: match 文字列 abd 命令と文字列を使って マッチング処理を行う 流れを説明します
③VMが命令を解釈して、文字列とマッチング 2. マッチング処理の流れ VM 命令(赤枠は処理中の命令 ) 0: char a 1
: split 2, 4 2: char b 3: jump 5 4: char c 5: char d 6: match 文字列 abd a 次の命令/文字に進める 比較
③VMが命令を解釈して、文字列とマッチング 2. マッチング処理の流れ VM 命令(赤枠は処理中の命令 ) 0: char a 1
: split 2, 4 2: char b 3: jump 5 4: char c 5: char d 6: match 文字列 b abd 2, 4の命令に分岐させる
③VMが命令を解釈して、文字列とマッチング 2. マッチング処理の流れ VM 命令(赤枠は処理中の命令 ) 0: char a 1
: split 2, 4 2: char b 3: jump 5 4: char c 5: char d 6: match 文字列 b 2, 4の命令に分岐させる b b abd
③VMが命令を解釈して、文字列とマッチング 2. マッチング処理の流れ VM 命令(赤枠は処理中の命令 ) 0: char a 1
: split 2, 4 2: char b 3: jump 5 4: char c 5: char d 6: match 文字列 b b abd 次の命令/文字に進める この分岐は終了 比較 比較
③VMが命令を解釈して、文字列とマッチング 2. マッチング処理の流れ VM 命令(赤枠は処理中の命令 ) 0: char a 1
: split 2, 4 2: char b 3: jump 5 4: char c 5: char d 6: match 文字列 d abd 5の命令に移動させる
③VMが命令を解釈して、文字列とマッチング 2. マッチング処理の流れ VM 命令(赤枠は処理中の命令 ) 0: char a 1
: split 2, 4 2: char b 3: jump 5 4: char c 5: char d 6: match 文字列 d abd 5の命令に移動させる d
③VMが命令を解釈して、文字列とマッチング 2. マッチング処理の流れ VM 命令(赤枠は処理中の命令 ) 0: char a 1
: split 2, 4 2: char b 3: jump 5 4: char c 5: char d 6: match 文字列 abd d 次の命令/文字に進める 比較
③VMが命令を解釈して、文字列とマッチング 2. マッチング処理の流れ VM 命令(赤枠は処理中の命令 ) 0: char a 1
: split 2, 4 2: char b 3: jump 5 4: char c 5: char d 6: match 文字列 abd match まで来たらマッチング成功
2. マッチング処理の流れ VM型正規表現エンジン AST a b c d or concat
パターン a(b|c)d 文字列 abd 命令 0: char a 1 : split 2, 4 2: char b 3: jump 5 4: char c 5: char d 6: match マッチング 成功 変換 変換 VM 命令を解釈して、 文字列とマッチング
し た ご清聴ありがとうございま