regex-tester
UtilityTest and debug regular expressions with match highlighting.
What it does
The agent tests regex patterns against sample text and shows exactly what matches (with positions, groups, and highlighted output). Can also build patterns from natural language descriptions, explain what a pattern does component-by-component, and replace text using regex.
How an agent uses it
- 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".
What you get
Install this skill and your Hermes agent can test and debug regular expressions with match highlighting. No manual setup, no scripts to run — the agent handles it.
Install command
hermes skills install https://raw.githubusercontent.com/THEROCKSSS/hermes-skills-portfolio/main/skills/regex-tester/SKILL.md
---
name: regex-tester
description: 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".
version: 1.0.0
author: Hermes Agent
license: MIT
metadata:
hermes:
tags: [regex, pattern-matching, text-processing, debugging]
related_skills: [json-formatter, log-analyzer, markdown-linter]
---
# 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
```python
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
```python
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:
```python
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
```python
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
```python
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
# regex-tester
Test, build, and debug regular expressions — with match highlighting and pattern explanations.
## What it does
The agent tests regex patterns against sample text and shows exactly what matches (with positions, groups, and highlighted output). Can also build patterns from natural language descriptions, explain what a pattern does component-by-component, and replace text using regex.
## Install
```bash
hermes skills install https://raw.githubusercontent.com/THEROCKSSS/hermes-skills-portfolio/main/skills/regex-tester/SKILL.md
```
## How to use
```
"Test the regex \d{3}-\d{4} against this text: Call 555-1234 or 987-6543"
```
The agent:
1. Compiles the pattern
2. Finds all matches
3. Returns: "2 matches: [555-1234] at pos 5, [987-6543] at pos 18"
## Common patterns included
| Pattern | Matches |
|---|---|
| email | Email addresses |
| url | HTTP/HTTPS URLs |
| ipv4 | IPv4 addresses |
| date_iso | YYYY-MM-DD dates |
| phone_us | US phone numbers |
| uuid | UUIDs |
| hex_color | #RRGGBB colors |
| semver | Semantic versions |
## Example
```
User: "Extract all email addresses from this text"
Agent:
1. Uses pattern: [a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}
2. Tests against the text
3. Returns: ["alice@example.com", "bob@work.org"]
```