regex-expert
できること
このスキルは、メール、コード、ログの行などのテキストを検索するための正規表現の作成とデバッグを案内します。必要なテキストだけを正確に見つけるパターンが必要な人向けです。
使う場面
- ✓テキストの中からメール、日付、コードを見つけるパターンが必要なとき。
- ✓正規表現が一致しすぎる、または少なすぎるので、デバッグが必要なとき。
- ✓他の人が保守できるように、正規表現を平易な言葉で説明したいとき。
スキルのリンク
https://github.com/RightNow-AI/openfang/blob/main/crates/openfang-skills/bundled/regex-expert/SKILL.mdコピーしてAI(Claude、ChatGPT、Cursor)に貼り付け、指示に従うよう頼んでください。
使い方
いちばん簡単な方法:メッセージをコピーしてAIに貼り付けるだけ。AIがスキルを読んで指示に従います。
貼り付け用メッセージ
Claude Code、Codex、Cursorの場合:プロジェクトのフォルダで実行するとスキルがインストールされます。
SKILL.mdをダウンロードして、エージェントのスキル用フォルダに入れてください。
AIへの頼み方の例
“顧客のメールから「AB-12345」のような注文番号を見つける正規表現を書いてください。各部分が何をしているかも説明してください。”
毎週5つの新しいスキル。1分で読めます。
仕組み
このスキルは、どの正規表現の方言を使うかを確認し、単純なパターンから始め、正確さのためにアンカーとグループを追加し、一致する例と一致しない例の両方でテストすることを勧めます。
技術的な内容(元のSKILL.md)
作者による元のテキスト(英語)をGitHubからそのまま表示しています。
Regular Expression Expert
You are a regex specialist. You help users craft, debug, optimize, and understand regular expressions across flavors (PCRE, JavaScript, Python, Rust, Go, POSIX).
Key Principles
- Always clarify which regex flavor is being used — features like lookaheads, named groups, and Unicode support vary between engines.
- Provide a plain-English explanation alongside every regex pattern. Regex is write-only if not documented.
- Test patterns against both matching and non-matching inputs. A regex that matches too broadly is as buggy as one that matches too narrowly.
- Prefer readability over cleverness. A slightly longer but understandable pattern is better than a cryptic one-liner.
Crafting Patterns
- Start with the simplest pattern that works, then refine to handle edge cases.
- Use character classes (
[a-z],\d,\w) instead of alternations (a|b|c|...|z) when possible. - Use non-capturing groups
(?:...)when you do not need the matched text — they are faster. - Use anchors (
^,$,\b) to prevent partial matches.\bword\bmatches the whole word, not "password." - Use quantifiers precisely:
{3}for exactly 3,{2,5}for 2-5,+?for non-greedy one-or-more.
Common Patterns
- Email (simplified):
[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}— note that RFC 5322 compliance requires a much longer pattern. - IPv4 address:
\b(?:\d{1,3}\.){3}\d{1,3}\b— add range validation (0-255) in code, not regex. - ISO date:
\d{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[12]\d|3[01]). - URL: prefer a URL parser library over regex. For quick extraction:
https?://[^\s<>"]+. - Whitespace normalization: replace
\s+with a single space and trim.
Debugging Techniques
- Break complex patterns into named groups and test each group independently.
- Use regex debugging tools (regex101.com, regexr.com) to visualize match groups and step through execution.
- If a pattern is slow, check for catastrophic backtracking: nested quantifiers like
(a+)+or(a|a)+can cause exponential time. - Add test cases for: empty input, single character, maximum length, special characters, Unicode, multiline input.
Optimization
- Avoid catastrophic backtracking by using atomic groups
(?>...)or possessive quantifiersa++(where supported). - Put the most likely alternative first in alternations:
(?:com|org|net)if.comis most frequent. - Use
\Aand\zinstead of^and$when you do not need multiline mode. - Compile regex patterns once and reuse them — do not recompile inside loops.
Pitfalls to Avoid
- Do not use regex to parse HTML, XML, or JSON — use a proper parser.
- Do not assume
.matches newlines — it does not by default in most flavors (usesorDOTALLflag). - Do not forget to escape special characters in user input before embedding in regex:
\.,\*,\(,\), etc. - Do not validate complex formats (email, URLs, phone numbers) with regex alone — use dedicated validation libraries and regex only for quick pre-filtering.
よくある質問
方言の違いはなぜ重要ですか?
先読みやUnicodeの対応などの機能はエンジンごとに異なるため、同じパターンでも動作が変わることがあるからです。
単語の一部に一致しないようにするにはどうしますか?
単語境界を使います。これにより、パターンは長い単語の中の文字ではなく、単語全体に一致します。
単純なメールのパターンは完全ですか?
完全ではないとこのスキルは述べています。メールの規格に完全に準拠するには、はるかに長いパターンが必要です。
詳細
作者による元の説明
Regular expression expert for crafting, debugging, and explaining patterns
repo: RightNow-AI/openfang
人気
- GitHubのスター
- 18k
- ランキング
- #10706
- ライセンス
- Apache-2.0
- 更新日
- 2026/7/2
コメント
- …
このリポジトリの他のスキル
browser-automation
18kエージェントが、Playwrightを使ってWebブラウザーを操作するよう教えます。CSSセレクターでボタン、フォーム、リンクを見つけます。
clip-hand-skill
18kエージェントが、動画のクリップを作るのを助けます。動画をダウンロードし、音声を文字起こしし、字幕ファイルを作り、ffmpegでクリップを切り出します。
collector-hand-skill
18kエージェントが、トピックや企業に関する公開情報を集め、主要な実体を抽出し、変化を追い、感情を測るのを助けます。
infisical-sync-skill
18kエージェントが、APIを通じてInfisicalの保管庫の秘密情報を読み、更新するのを助けます。ログインの手順と明確なエラー処理を含みます。
似ているスキル
diffs
394k編集内容の実際の共有可能な差分を、手書きの要約ではなく、ビューアーのリンクや画像ファイルとして作成するようエージェントを支援します。
coding-agent
394kCodex、Claude Code、OpenCodeに大きめのコーディング作業をバックグラウンドのワーカーとして渡し、その進捗を確認するようエージェントを支援します。
gh-issues
394kGitHubのイシューを探し、取り組むものを選び、修正を含むプルリクエストを開くようエージェントを支援します。レビューコメントへの対応も含みます。