OpenParable
Skip to content
← Back to skills

Regex

Development
regex

Regex is an Agent Skill for development published in the microclaw/microclaw repository on GitHub: a SKILL.md instruction file an AI agent can load to do this task.

Write, explain, test, and debug regular expressions, and build them iteratively against real sample input. Use when users want a regex/pattern to match or extract text, ask why a pattern isn't matching, need to validate emails/URLs/dates/phone numbers, or want to do find-and-replace with capture groups. Triggers on mentions of regex, regular expression, pattern, match, extract, validate, find and replace, 正则, 正则表达式, 匹配, 提取, 替换.

View on GitHub ↗
QUICK START

How to use this skill

Bring this guide into your coding agent with a prompt tailored to the tool you use.

  1. Open your project in Codex.
  2. Copy and paste the prompt below.
  3. Review files and risks before approving any action.
Prompt to paste
Inspect the Agent Skill at https://github.com/microclaw/microclaw/blob/HEAD/skills/built-in/regex/SKILL.md and all supporting files. Report provenance, permissions, scripts, dependencies, and security risks. Propose an exact installation into .agents/skills/regex, but wait for my approval before writing files or running scripts.

Copying this prompt does not install or run the skill. Review third-party files before use.

Regex

Never hand-wave a regex — test it against real samples before handing it over. A pattern that "looks right" but fails on the user's actual input is worse than no pattern.

Test a pattern against samples

python3 - <<'PY'
import re
pat = r'\b\d{4}-\d{2}-\d{2}\b'
samples = ["due 2026-05-31 ok", "no date", "2026/05/31 wrong sep"]
for s in samples:
    print(repr(s), "->", re.findall(pat, s))
PY

Extract with named groups

python3 - <<'PY'
import re
m = re.search(r'(?P<user>[\w.+-]+)@(?P<domain>[\w.-]+)', "ping [email protected]")
print(m.groupdict() if m else "no match")
PY

Find-and-replace with backreferences

python3 - <<'PY'
import re
print(re.sub(r'(\d{4})-(\d{2})-(\d{2})', r'\3/\2/\1', "2026-05-31"))  # -> 31/05/2026
PY

Common building blocks

  • Anchors: ^ start, $ end, \b word boundary.
  • Classes: \d digit, \w word char, \s space; negate with uppercase \D \W \S.
  • Quantifiers: * 0+, + 1+, ? 0/1, {m,n}; add ? for lazy (.*?).
  • Groups: (...) capture, (?:...) non-capture, (?P<name>...) named.
  • Lookaround: (?=...), (?!...), (?<=...), (?<!...).

Guidance

  • Always show what it matches AND what it deliberately rejects, using the user's samples.
  • Prefer explicit, readable patterns over clever unreadable ones; add re.VERBOSE for complex patterns and comment them.
  • Warn about catastrophic backtracking (nested quantifiers like (a+)+) on untrusted input.
  • Note the regex flavor if it leaves Python (JS, PCRE, Go/RE2, grep) — escaping and lookbehind support differ.