本文へスキップ
Skillpedia
一般的なプログラミング18k · #10706

regex-expert

できること

このスキルは、メール、コード、ログの行などのテキストを検索するための正規表現の作成とデバッグを案内します。必要なテキストだけを正確に見つけるパターンが必要な人向けです。

使う場面

  • ✓テキストの中からメール、日付、コードを見つけるパターンが必要なとき。
  • ✓正規表現が一致しすぎる、または少なすぎるので、デバッグが必要なとき。
  • ✓他の人が保守できるように、正規表現を平易な言葉で説明したいとき。

スキルのリンク

https://github.com/RightNow-AI/openfang/blob/main/crates/openfang-skills/bundled/regex-expert/SKILL.md

コピーしてAI(Claude、ChatGPT、Cursor)に貼り付け、指示に従うよう頼んでください。

使い方

いちばん簡単な方法:メッセージをコピーしてAIに貼り付けるだけ。AIがスキルを読んで指示に従います。

貼り付け用メッセージ

このスキルを使って手伝ってください:https://github.com/RightNow-AI/openfang/blob/main/crates/openfang-skills/bundled/regex-expert/SKILL.md このリンクのSKILL.mdファイルを読んで、私の作業でその指示に従ってください。
こういうスキルを、AIが自分で見つけてくれたら?無料のSkillpedia MCPをインストール。1行で、作業の前に15,000+のスキルから探してくれます。1分でインストール →

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\b matches 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 quantifiers a++ (where supported).
  • Put the most likely alternative first in alternations: (?:com|org|net) if .com is most frequent.
  • Use \A and \z instead 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 (use s or DOTALL flag).
  • 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

このスキルは役に立ちますか?

0

ログイン して投票しましょう。

コメント

  • …

このリポジトリの他のスキル

似ているスキル