regex
正規表現の構文やパターン、言語ごとの使い方を習得し、複雑な文字列処理やデータ抽出を効率的に行うSkill。
📜 元の英語説明(参考)
Regular expression mastery with syntax, common patterns, and language-specific usage. Use when user asks to "write a regex", "match pattern", "validate email", "extract data with regex", "parse string", "regex for phone number", or any regular expression tasks.
🇯🇵 日本人クリエイター向け解説
正規表現の構文やパターン、言語ごとの使い方を習得し、複雑な文字列処理やデータ抽出を効率的に行うSkill。
※ jpskill.com 編集部が日本のビジネス現場向けに補足した解説です。Skill本体の挙動とは独立した参考情報です。
下記のコマンドをコピーしてターミナル(Mac/Linux)または PowerShell(Windows)に貼り付けてください。 ダウンロード → 解凍 → 配置まで全自動。
mkdir -p ~/.claude/skills && cd ~/.claude/skills && curl -L -o regex.zip https://jpskill.com/download/6122.zip && unzip -o regex.zip && rm regex.zip
$d = "$env:USERPROFILE\.claude\skills"; ni -Force -ItemType Directory $d | Out-Null; iwr https://jpskill.com/download/6122.zip -OutFile "$d\regex.zip"; Expand-Archive "$d\regex.zip" -DestinationPath $d -Force; ri "$d\regex.zip"
完了後、Claude Code を再起動 → 普通に「動画プロンプト作って」のように話しかけるだけで自動発動します。
💾 手動でダウンロードしたい(コマンドが難しい人向け)
- 1. 下の青いボタンを押して
regex.zipをダウンロード - 2. ZIPファイルをダブルクリックで解凍 →
regexフォルダができる - 3. そのフォルダを
C:\Users\あなたの名前\.claude\skills\(Win)または~/.claude/skills/(Mac)へ移動 - 4. Claude Code を再起動
⚠️ ダウンロード・利用は自己責任でお願いします。当サイトは内容・動作・安全性について責任を負いません。
🎯 このSkillでできること
下記の説明文を読むと、このSkillがあなたに何をしてくれるかが分かります。Claudeにこの分野の依頼をすると、自動で発動します。
📦 インストール方法 (3ステップ)
- 1. 上の「ダウンロード」ボタンを押して .skill ファイルを取得
- 2. ファイル名の拡張子を .skill から .zip に変えて展開(macは自動展開可)
- 3. 展開してできたフォルダを、ホームフォルダの
.claude/skills/に置く- · macOS / Linux:
~/.claude/skills/ - · Windows:
%USERPROFILE%\.claude\skills\
- · macOS / Linux:
Claude Code を再起動すれば完了。「このSkillを使って…」と話しかけなくても、関連する依頼で自動的に呼び出されます。
詳しい使い方ガイドを見る →- 最終更新
- 2026-05-17
- 取得日時
- 2026-05-17
- 同梱ファイル
- 1
📖 Skill本文(日本語訳)
※ 原文(英語/中国語)を Gemini で日本語化したものです。Claude 自身は原文を読みます。誤訳がある場合は原文をご確認ください。
正規表現
正規表現の構文、パターン、およびレシピです。
コア構文
文字クラス
. 任意の一文字(改行を除く)
\d 数字 [0-9]
\D 非数字
\w 単語文字 [a-zA-Z0-9_]
\W 非単語文字
\s 空白文字 [ \t\n\r\f]
\S 非空白文字
[abc] 文字セット (a、b、または c)
[^abc] 否定セット (a、b、または c 以外)
[a-z] 範囲 (a から z)
[a-zA-Z] 複数の範囲
量指定子
* 0 回以上
+ 1 回以上
? 0 回または 1 回
{3} 正確に 3 回
{3,} 3 回以上
{3,5} 3 回から 5 回
*? 0 回以上 (非貪欲)
+? 1 回以上 (非貪欲)
?? 0 回または 1 回 (非貪欲)
アンカーと境界
^ 文字列の先頭 (m フラグがある場合は行の先頭)
$ 文字列の末尾 (m フラグがある場合は行の末尾)
\b 単語の境界
\B 非単語の境界
グループと参照
(abc) キャプチャグループ
(?:abc) 非キャプチャグループ
(?<name>abc) 名前付きキャプチャグループ
\1 グループ 1 への後方参照
(?=abc) 肯定先読み
(?!abc) 否定先読み
(?<=abc) 肯定後読み
(?<!abc) 否定後読み
選択とエスケープ
a|b a または b にマッチ
\ 特殊文字をエスケープ
\. リテラルなドット
\* リテラルなアスタリスク
フラグ
g グローバル (すべてのマッチ)
i 大文字と小文字を区別しない
m 複数行 (^ と $ が行の境界にマッチ)
s ドットオール (. が改行にマッチ)
u Unicode
x 拡張 (空白を無視し、コメントを許可)
一般的なパターン
バリデーション
# メールアドレス (簡易版)
^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$
# URL
^https?://[^\s/$.?#].[^\s]*$
# 電話番号 (米国)
^\+?1?[-.\s]?\(?\d{3}\)?[-.\s]?\d{3}[-.\s]?\d{4}$
# IPアドレス (IPv4)
^(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)$
# 日付 (YYYY-MM-DD)
^\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])$
# 時刻 (HH:MM, 24時間制)
^([01]\d|2[0-3]):[0-5]\d$
# UUID
^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$
# 16進数カラーコード
^#?([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$
# 強力なパスワード (8文字以上、大文字、小文字、数字、特殊文字)
^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]{8,}$
# セマンティックバージョニング
^v?(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-([\da-zA-Z-]+(?:\.[\da-zA-Z-]+)*))?$
# スラッグ (URLセーフな文字列)
^[a-z0-9]+(?:-[a-z0-9]+)*$
抽出
# URLからドメインを抽出
https?://([^/\s]+)
# パスからファイル名を抽出
[^/\\]+$
# 文字列から数字を抽出
\d+\.?\d*
# HTMLタグを抽出
<([a-zA-Z][a-zA-Z0-9]*)\b[^>]*>
# key=value のペアを抽出
(\w+)=([^\s&]+)
# Markdownリンクを抽出
\[([^\]]+)\]\(([^)]+)\)
# CSVフィールドを抽出 (引用符の処理を含む)
(?:^|,)(?:"([^"]*(?:""[^"]*)*)"|([^,]*))
言語ごとの使用法
JavaScript
// テスト
/^\d+$/.test("123"); // true
// マッチ
"hello world".match(/(\w+)\s(\w+)/); // ["hello world", "hello", "world"]
// すべてのマッチ
[..."text 123 more 456".matchAll(/\d+/g)]; // [["123"], ["456"]]
// 置換
"hello".replace(/l/g, "r"); // "herro"
"John Smith".replace(/(\w+) (\w+)/, "$2, $1"); // "Smith, John"
// 分割
"a,b,,c".split(/,+/); // ["a", "b", "c"]
// 名前付きグループ
const m = "2024-01-15".match(/(?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2})/);
m.groups.year; // "2024"
Python
import re
# マッチ (先頭から)
re.match(r'^\d+', '123abc')
# 検索 (どこでも)
re.search(r'\d+', 'abc123')
# すべて検索
re.findall(r'\d+', 'a1 b2 c3') # ['1', '2', '3']
# グループを含むすべて検索
re.findall(r'(\w+)=(\w+)', 'a=1 b=2') # [('a', '1'), ('b', '2')]
# 置換
re.sub(r'\d+', 'X', 'a1b2c3') # 'aXbXcX'
re.sub(r'(\w+) (\w+)', r'\2 \1', 'John Smith') # 'Smith John'
# 再利用のためにコンパイル
pattern = re.compile(r'\b\w{4}\b')
pattern.findall('the quick brown fox') # ['quick', 'brown']
# 名前付きグループ
m = re.search(r'(?P<year>\d{4})-(?P<month>\d{2})', '2024-01')
m.group('year') // '2024'
# フラグ
re.findall(r'hello', 'Hello World', re.IGNORECASE)
Bash/grep
# grep (基本正規表現)
grep "pattern" file.txt
grep -i "pattern" file.txt # 大文字と小文字を区別しない
grep -E "extended|regex" file.txt # 拡張正規表現
grep -P "\d{3}" file.txt # Perl正規表現 (GNU grep)
# sed
sed 's/old/new/g' file.txt
sed -E 's/([0-9]+)/[\1]/g' file.txt
参照
その他のレシピとテストのヒントについては、references/recipes.md をご覧ください。
📜 原文 SKILL.md(Claudeが読む英語/中国語)を展開
Regular Expressions
Regex syntax, patterns, and recipes.
Core Syntax
Character Classes
. Any character (except newline)
\d Digit [0-9]
\D Non-digit
\w Word character [a-zA-Z0-9_]
\W Non-word character
\s Whitespace [ \t\n\r\f]
\S Non-whitespace
[abc] Character set (a, b, or c)
[^abc] Negated set (not a, b, or c)
[a-z] Range (a through z)
[a-zA-Z] Multiple ranges
Quantifiers
* 0 or more
+ 1 or more
? 0 or 1
{3} Exactly 3
{3,} 3 or more
{3,5} 3 to 5
*? 0 or more (lazy/non-greedy)
+? 1 or more (lazy)
?? 0 or 1 (lazy)
Anchors & Boundaries
^ Start of string (or line with m flag)
$ End of string (or line with m flag)
\b Word boundary
\B Non-word boundary
Groups & References
(abc) Capture group
(?:abc) Non-capturing group
(?<name>abc) Named capture group
\1 Backreference to group 1
(?=abc) Positive lookahead
(?!abc) Negative lookahead
(?<=abc) Positive lookbehind
(?<!abc) Negative lookbehind
Alternation & Escaping
a|b Match a or b
\ Escape special character
\. Literal dot
\* Literal asterisk
Flags
g Global (all matches)
i Case-insensitive
m Multiline (^ and $ match line boundaries)
s Dotall (. matches newline)
u Unicode
x Extended (ignore whitespace, allow comments)
Common Patterns
Validation
# Email (simplified)
^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$
# URL
^https?://[^\s/$.?#].[^\s]*$
# Phone (US)
^\+?1?[-.\s]?\(?\d{3}\)?[-.\s]?\d{3}[-.\s]?\d{4}$
# IP Address (IPv4)
^(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)$
# Date (YYYY-MM-DD)
^\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])$
# Time (HH:MM, 24hr)
^([01]\d|2[0-3]):[0-5]\d$
# UUID
^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$
# Hex color
^#?([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$
# Strong password (8+ chars, upper, lower, digit, special)
^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]{8,}$
# Semantic version
^v?(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-([\da-zA-Z-]+(?:\.[\da-zA-Z-]+)*))?$
# Slug (URL-safe string)
^[a-z0-9]+(?:-[a-z0-9]+)*$
Extraction
# Extract domain from URL
https?://([^/\s]+)
# Extract filename from path
[^/\\]+$
# Extract numbers from string
\d+\.?\d*
# Extract HTML tags
<([a-zA-Z][a-zA-Z0-9]*)\b[^>]*>
# Extract key=value pairs
(\w+)=([^\s&]+)
# Extract markdown links
\[([^\]]+)\]\(([^)]+)\)
# Extract CSV fields (handling quotes)
(?:^|,)(?:"([^"]*(?:""[^"]*)*)"|([^,]*))
Language Usage
JavaScript
// Test
/^\d+$/.test("123"); // true
// Match
"hello world".match(/(\w+)\s(\w+)/); // ["hello world", "hello", "world"]
// Match all
[..."text 123 more 456".matchAll(/\d+/g)]; // [["123"], ["456"]]
// Replace
"hello".replace(/l/g, "r"); // "herro"
"John Smith".replace(/(\w+) (\w+)/, "$2, $1"); // "Smith, John"
// Split
"a,b,,c".split(/,+/); // ["a", "b", "c"]
// Named groups
const m = "2024-01-15".match(/(?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2})/);
m.groups.year; // "2024"
Python
import re
# Match (from start)
re.match(r'^\d+', '123abc')
# Search (anywhere)
re.search(r'\d+', 'abc123')
# Find all
re.findall(r'\d+', 'a1 b2 c3') # ['1', '2', '3']
# Find all with groups
re.findall(r'(\w+)=(\w+)', 'a=1 b=2') # [('a', '1'), ('b', '2')]
# Replace
re.sub(r'\d+', 'X', 'a1b2c3') # 'aXbXcX'
re.sub(r'(\w+) (\w+)', r'\2 \1', 'John Smith') # 'Smith John'
# Compile for reuse
pattern = re.compile(r'\b\w{4}\b')
pattern.findall('the quick brown fox') # ['quick', 'brown']
# Named groups
m = re.search(r'(?P<year>\d{4})-(?P<month>\d{2})', '2024-01')
m.group('year') # '2024'
# Flags
re.findall(r'hello', 'Hello World', re.IGNORECASE)
Bash/grep
# grep (basic regex)
grep "pattern" file.txt
grep -i "pattern" file.txt # Case insensitive
grep -E "extended|regex" file.txt # Extended regex
grep -P "\d{3}" file.txt # Perl regex (GNU grep)
# sed
sed 's/old/new/g' file.txt
sed -E 's/([0-9]+)/[\1]/g' file.txt
Reference
For more recipes and testing tips: references/recipes.md