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
正規表現 / RegExp_2021
Search
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
Cybozu
PRO
June 02, 2021
Technology
12k
3
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
正規表現 / RegExp_2021
Cybozu
PRO
June 02, 2021
More Decks by Cybozu
See All by Cybozu
サイボウズ 開発本部採用ピッチ / Cybozu Engineer Recruit
cybozuinsideout
PRO
12
94k
新卒1年目QAが リリース基準の"なぜ"をたどってみた
cybozuinsideout
PRO
1
950
kintone リサーチ副部/UXリサーチャー 業務紹介
cybozuinsideout
PRO
0
200
私たちが『JaSST協賛』から『外部コネクト』チームになった理由
cybozuinsideout
PRO
0
620
LLMでもいつものテスト技術〜意外と半分はこれまでのテストでした〜
cybozuinsideout
PRO
1
1.2k
kintone開発のプラットフォームエンジニアの紹介
cybozuinsideout
PRO
1
1.8k
LLMアプリの品質保証
cybozuinsideout
PRO
1
900
技術広報チームに丸投げしない!「一緒につくる」スポンサー活動
cybozuinsideout
PRO
0
320
テクニカルライター (グループウェア) について
cybozuinsideout
PRO
0
320
Other Decks in Technology
See All in Technology
dbt Semantic Layerで進めるenechainのデータ民主化
akizhou
1
190
Active Record Connection Adaptersにおける長年の課題に再び取り組む
yahonda
0
400
CSS2026:OWS研究会・招待講演「世界観を、実装する」
atsush1_sada
2
110
20年間 SNS サービス「GREE」 を支えた技術の刷新と、長期運用サービスの Kubernetes へのリアーキテクト
gree_tech
PRO
0
110
[EMNLP26] RIGEL: Self-Distilled Score Adaptation for Image and Video Captioning Evaluation
keio_smilab
PRO
0
110
What Is JetBrains Air
x5gtrn
PRO
0
130
CTO Night|NotionのAIエージェントとFDE
kzkhykw1991
0
300
日本語に強いオープンな大規模言語モデル「LLM-jp」
odashi
5
1.2k
10年後、Engineering 行為を剥奪されるとして、わたしたちは、どう、何を創ればいいだろうか。 / If Engineering Is Taken Away in 10 Years, How and What Should We Create?
bitkey
PRO
1
220
アウトプット初心者、半年間のふりかえり
4o1sobblue
0
460
FinOps Agentが生んだ技術負債:コスト自動調査の落とし穴と解消までの道のり
oasis1994liveforever
3
250
~最速でビジネスインパクトを創出する~ Sansanのデータ基盤と活用事例
sansantech
PRO
0
110
Featured
See All Featured
Jess Joyce - The Pitfalls of Following Frameworks
techseoconnect
PRO
1
450
How to Ace a Technical Interview
jacobian
280
24k
Leading Effective Engineering Teams in the AI Era
addyosmani
9
2.8k
Agile Leadership in an Agile Organization
kimpetersen
PRO
0
290
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
230
23k
How to build a perfect <img>
jonoalderson
1
6.1k
Fashionably flexible responsive web design (full day workshop)
malarkey
409
67k
Heart Work Chapter 1 - Part 1
lfama
PRO
10
37k
Building a A Zero-Code AI SEO Workflow
portentint
PRO
0
790
The Spectacular Lies of Maps
axbom
PRO
1
1.1k
The AI Revolution Will Not Be Monopolized: How open-source beats economies of scale, even for LLMs
inesmontani
PRO
3
3.8k
The Art of Programming - Codeland 2020
erikaheidi
57
14k
Transcript
正規表現 サイボウズ株式会社
名前とは︖ ▌全てをリストアップしようとしたら 切りがない ▌「何でも良い」というわけにもい かない ▌(なるべく)全てを表現するパ ターンを使う
正規表現の利⽤例 ▌バリデーション n ⼊⼒された⽂字列が期待通りの形式か n 例)メールアドレス欄に電話番号を⼊⼒していないか ▌抽出 n ⼤量のテキストデータから参照したい部分だけを抽出する n
例)アクセスログからIPアドレスだけを抽出するとか
基本な正規表現: ⽂字列 ▌連続する⽂字列 n 例)cybozu n cybozu.com n hoge.cybozu.com n
hoge.cybozu-dev.com
基本な正規表現: 選択・グループ ▌| 区切りでどれかにマッチさせる ▌() で選択範囲を限定する n 例)com|cn n cybozu.com
n cybozu.cn n (cybozu|kintone).com n cybozu.com n kintone.com n cybozu1com ←あれ︖
基本な正規表現 ▌. 1⽂字(何でも良い) ▌¥ ¥の次の特別⽂字をそのまま使う n 例)(cybozu|kintone)¥.com ▌[ab] ⽂字クラス。[]の中の1⽂字をマッチする ▌[^ab]
否定⽂字クラス。[]の中が含まれなかったらマッチする ▌[a-z] aからzまでの⽂字クラス
特別クラス ▌¥d 数字 →[0-9] ▌¥D ⾮数字 →[^0-9] ▌¥w ⽂字(数字を含む) →[a-zA-Z0-9_]
▌¥W ⾮⽂字 →[^a-zA-Z0-9_]
基本な正規表現: 繰り返し ▌? 0-1回繰り返しマッチする ▌+ 1回以上繰り返しマッチする ▌* 0回以上繰り返しマッチする ▌{min, max}
min回以上、max回以下 n 例).+¥.cybozu(-dev)?.com n ocean.cybozu-dev.com n hoge.cybozu.com n example.com/www.cybozu.com ←あれ︖
名前とは︖ ▌[A-Z][a-z]* ▌本当︖ ▌「Taro Jr.」 は︖ ▌正規表現って難しい
基本な正規表現:先頭と末尾 ▌^ ⾏の先頭にマッチ ▌$ ⾏の末尾にマッチ ▌^hoge.[a-z].com$ n hoge.cybozu.com n hoge.hoge.com
n nothoge.cybozu.com
後⽅参照 ▌¥1, ¥2, ¥n n番⽬の()内のマッチしたものと同じ⽂字列 ▌<(div|p)>.*<¥/¥1> n <div>hoge</div> n <p>hoge</p>
後⽅参照(2) ▌(?:hoge) マッチはするが、¥1には⼊らない ▌(?<name>hoge)(?P=name) 名前付き後⽅参照グループ
メールアドレスとは︖ ▌ (?:[a-z0-9!#$%&'*+¥/=?^_`{|}~-]+(?:¥.[a- z0-9!#$%&'*+¥/=?^_`{|}~-]+)*|"(?:[¥x01- ¥x08¥x0b¥x0c¥x0e-¥x1f¥x21¥x23- ¥x5b¥x5d-¥x7f]|¥¥[¥x01- ¥x09¥x0b¥x0c¥x0e-¥x7f])*")@(?:(?:[a- z0-9](?:[a-z0-9-]*[a-z0-9])?¥.)+[a-z0- 9](?:[a-z0-9-]*[a-z0-9])?|¥[(?:(?:(2(5[0- 5]|[0-4][0-9])|1[0-9][0-9]|[1-9]?[0-
9]))¥.){3}(?:(2(5[0-5]|[0-4][0-9])|1[0-9][0- 9]|[1-9]?[0-9])|[a-z0-9-]*[a-z0- 9]:(?:[¥x01-¥x08¥x0b¥x0c¥x0e-¥x1f¥x21- ¥x5a¥x53-¥x7f]|¥¥[¥x01- ¥x09¥x0b¥x0c¥x0e-¥x7f])+)¥]) ▌ 正規表現って難しい
ツール紹介 業務で恐らく使う事になる場⾯
awk ▌テキスト抽出⽤のプログラミング⾔語・コマンドラインツール ▌Aho, Weinberger, Kernighan ▌正規表現も使える ▌例)ip a s |
awk '/inet/{print $2}' n ip a s の結果に「inet」の含んだ⾏だけに対して2列⽬を抽出する
sed ▌Stream editor ▌ファイルを読み上げて書き換えられる ▌例) sed -i 's/2018/2021/g' kaiun.md ▌今年の資料を作るなら
sed -i 's/2019/2021/g' kaiun.md n kaiun.mdというファイルの中⾝から「2019」という⽂字を全て「2021」に する
grep ▌globally search a regular expression and print ▌全⽂検索してマッチした正規表現をプリントする ▌例)
grep -P "¥d+¥.¥d+¥.¥d+¥.¥d+" /var/log/nginx/error.log n nginxのエラーログからIPアドレスを表⽰する
git-grep ▌https://git-scm.com/docs/git-grep ▌gitレポにあるファイルをgrepする ▌例) git grep -B1 -E "IN¥W+SPF"
普段使っているツールにも ▌CLIでless等を使う場合、結果から正規表現で絞り込む事ができる ▌VSCodeの検索機能には正規表現を使った検索もできる ▌勿論プログラミング⾔語にも n https://github.com/cybozu-go/neco/blob/master/pkg/git- neco/cmd/github.go#L63 n https://github.com/kintone/kintone- cli/blob/master/src/utils/string.ts
お勧め ▌http://shop.oreilly.com/product/9780596003524.do ▌https://blog.cybozu.io/entry/8757 ▌https://regexcrossword.com/ ▌https://regex101.com/
演習 ▌https://regexcrossword.com/ で遊ぶ ▌↓の出⼒からHTTPヘッダーを抽出する n curl -v https://hoge.cybozu-dev.com