agentleFS
THEROCKSSSTHEROCKSSS/hermes-skills-portfolio/skills/regex-tester/SKILL.md

regex-tester

Skill1 starsChanged 3 months agoMITView on GitHub

Use when the user wants to test a regex pattern against sample text, needs a regex built from a natural-language description, or has a regex that isn't matching as expected — triggers include "test this regex", "write a regex for", or "why isn't my regex working".

1 other project uses a version of this.

Adopted by

Most recently taken up by

The file

We split this skill into the rules it gives an agent

3 rules. About 0 are common, 3 are distinctive, and 0 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈3

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 0

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Test, debug, and build regular expressions.

    line 17
  2. Distinctive:

    Test the pattern against sample text

    line 159
  3. Distinctive:

    If no matches, debug: explain the pattern and suggest fixes

    line 161

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

regex-tester

Overview

Test, debug, and build regular expressions. The agent creates regex patterns from descriptions, tests them against sample text, explains what they match, and helps fix patterns that don't work as expected.

When to Use

  • The user wants to test a regex pattern against text.
  • The user needs help writing a regex for a specific pattern.
  • The user has a regex that isn't matching correctly.
  • The user says "test this regex", "write a regex for", or "why isn't my regex working".

Test a Regex

import re

def test_regex(pattern: str, text: str, flags: list = None) -> dict:
    """Test a regex pattern against text and return detailed results."""
    flag = 0
    if flags:
        if 'i' in flags: flag |= re.IGNORECASE
        if 'm' in flags: flag |= re.MULTILINE
        if 's' in flags: flag |= re.DOTALL
        if 'x' in flags: flag |= re.VERBOSE

    try:
        compiled = re.compile(pattern, flag)
    except re.error as e:
        return {"valid": False, "error": str(e), "pattern": pattern}

    matches = list(compiled.finditer(text))

    return {
        "valid": True,
        "pattern": pattern,
        "match_count": len(matches),
        "matches": [
            {
                "match": m.group(0),
                "start": m.start(),
                "end": m.end(),
                "groups": m.groups(),
                "named_groups": m.groupdict(),
            }
            for m in matches
        ],
        "highlighted": highlight_matches(text, matches),
    }

def highlight_matches(text: str, matches) -> str:
    """Return text with matches wrapped in markers."""
    result = []
    last_end = 0
    for m in matches:
        result.append(text[last_end:m.start()])
        result.append(f"[{m.group(0)}]")
        last_end = m.end()
    result.append(text[last_end:])
    return ''.join(result)

Common Patterns

PATTERNS = {
    "email": r"[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}",
    "url": r"https?://[^\s<>"']+[^\s<>"'.]",
    "ipv4": r"\b(?:\d{1,3}\.){3}\d{1,3}\b",
    "ipv6": r"(?:[A-F0-9]{1,4}:){7}[A-F0-9]{1,4}",
    "phone_us": r"\+?1?[-.\s]?\(?(\d{3})\)?[-.\s]?(\d{3})[-.\s]?(\d{4})",
    "date_iso": r"\d{4}-\d{2}-\d{2}",
    "date_us": r"\d{1,2}/\d{1,2}/\d{2,4}",
    "time": r"\d{1,2}:\d{2}(?::\d{2})?(?:\s?[AP]M)?",
    "uuid": r"[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}",
    "hex_color": r"#[0-9a-fA-F]{6}\b",
    "credit_card": r"\b(?:\d[ -]*?){13,16}\b",
    "zipcode_us": r"\b\d{5}(?:-\d{4})?\b",
    "semver": r"\d+\.\d+\.\d+(?:-[a-zA-Z0-9.]+)?(?:\+[a-zA-Z0-9.]+)?",
    "mac_address": r"([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})",
}

Build Regex from Description

The agent can construct patterns from natural language descriptions:

def build_regex(description: str) -> str:
    """Build a regex from a natural language description.
    This is a guide — the agent constructs the pattern based on understanding."""
    # The agent interprets the description and constructs the pattern
    # Examples of what the agent can build:
    examples = {
        "match email addresses": PATTERNS["email"],
        "find all urls": PATTERNS["url"],
        "extract dates in YYYY-MM-DD format": PATTERNS["date_iso"],
        "match a phone number": PATTERNS["phone_us"],
        "find hex color codes": PATTERNS["hex_color"],
        "match semver versions": PATTERNS["semver"],
    }
    return examples  # The agent selects or constructs the appropriate pattern

Explain a Regex

def explain_regex(pattern: str) -> str:
    """Break down a regex pattern into human-readable components."""
    explanations = {
        r'\d': "any digit (0-9)",
        r'\w': "any word character (a-z, A-Z, 0-9, _)",
        r'\s': "any whitespace",
        r'.': "any character",
        r'*': "zero or more of the preceding",
        r'+': "one or more of the preceding",
        r'?': "zero or one of the preceding",
        r'{n}': "exactly n of the preceding",
        r'{n,m}': "between n and m of the preceding",
        r'^': "start of string/line",
        r'$': "end of string/line",
        r'[]': "character class",
        r'()': "capture group",
        r'(?:)': "non-capturing group",
        r'(?=)': "lookahead",
        r'(?!)': "negative lookahead",
        r'|': "alternation (OR)",
        r'\\': "literal backslash",
    }
    # The agent walks through the pattern and explains each component
    return "See pattern breakdown in the response"

Replace with Regex

def regex_replace(pattern: str, text: str, replacement: str, count: int = 0) -> str:
    """Replace matches with a replacement string."""
    return re.sub(pattern, replacement, text, count=count or 0)

Workflow

  1. Understand what the user wants to match
  2. Either the user provides a pattern to test, or the agent builds one
  3. Test the pattern against sample text
  4. Show matches with positions and groups
  5. If no matches, debug: explain the pattern and suggest fixes
  6. Return the working pattern and match results

Common Pitfalls

  1. Greedy vs. lazy confusion. .* is greedy (matches as much as possible); .*? is lazy (matches as little as possible) — the most common regex bug.
  2. Missing anchors. Without ^ and $, the pattern matches anywhere in the string, not the whole thing — add anchors when a full-string match is intended.
  3. Unescaped special characters. . matches any character; to match a literal dot use \. — a frequent source of over-broad matches.
  4. Catastrophic backtracking. Nested quantifiers like (a+)+ can cause exponential matching time on certain inputs — avoid nesting quantifiers.
  5. Character class range mistakes. [a-z] is lowercase only; [A-Za-z] covers both cases; [\w] also includes digits and underscore.
  6. Unicode surprises. \w in Python 3 matches Unicode word characters by default — use [a-zA-Z0-9_] when ASCII-only matching is required.

Verification Checklist

  • Pattern compiles without a re.error
  • Tested against both matching and non-matching sample inputs, not just the happy path
  • Match count and capture groups match what the user described wanting
  • Checked for catastrophic backtracking risk if the pattern has nested quantifiers
  • Anchoring (^/$) behavior matches whether a full-string or partial match was intended

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.