Write a regular expression
Builds a regular expression from plain-language intent and example strings, explains each part and lists the edge cases it accepts or rejects. Use when you need a tested pattern.
Regexes look right and fail quietly. The common faults are a missing anchor that lets the pattern match inside a longer string, a feature the target engine does not support, a $ that also matches before a trailing newline, nested quantifiers that backtrack catastrophically on hostile input, and a pattern that was never actually run against the examples it was built from.
Write a regular expression for:
Must match:
Must not match:
- Decide the mode from the intent: full-string validation (anchor both ends), search within text (word boundaries or lookarounds), or extraction (capture groups, named if the engine supports them).
- Respect the engine:
- javascript: use the
uflag for Unicode;\dand\ware ASCII-only. - python: use
re.fullmatchfor validation, or\Zrather than$; in Python 3,\dand\wmatch Unicode unless you passre.ASCII. - pcre:
$matches before a final newline; use\zfor a strict end. Possessive quantifiers and atomic groups are available. - go: RE2 has no lookaround and no backreferences. Rewrite the logic without them, or say that code must do that part.
- posix: ERE only. No
\d, lazy quantifiers or lookaround; use bracket expressions like[0-9]and[[:alpha:]].
- Prefer the simplest pattern that passes every example. Avoid nested quantifiers over overlapping classes such as
(a+)+or(\w|\d)*. - Test it. Walk every example through the pattern and record the result. If a code tool is available, run them for real and say so. If any example fails, fix the pattern and repeat.
- Probe the edges the examples do not cover: empty string, leading and trailing whitespace, newlines, Unicode letters and digits, very long input, and near-misses of the valid shape.
- If the examples contradict the intent or each other, say which ones and which reading you followed.
- Never claim an example passes unless you checked it.
- If a regex is the wrong tool (nested structures, full email RFC compliance, real date validity such as 31 February, HTML), say so in one sentence, give the pragmatic pattern anyway, and name what code must check.
- Show the pattern both as a literal and as an escaped string for the language when they differ.
- Separate what you verified from what you inferred. Mark inferences as such.
- When you do not know, say "I don't know" once and state what would settle it.
Pattern
A code block with the pattern and flags, then one line on the matching mode.
How it works
| Part | Meaning |
Test results
| Input | Expected | Result | Every given example, then the edge cases you added.
Edge cases
Inputs it accepts that someone might not expect, and inputs it rejects that might be valid. One line each.
Usage
A 3 to 6 line snippet in the language of the chosen flavor (shell grep -E for posix).
Abridged to two sections; a real answer includes all five.
Intent: a hex colour in CSS, full-string. Should match: #fff, #A1B2C3. Should not match: fff, #abcd, #12345g. Flavor: javascript.
Pattern
/^#(?:[0-9a-f]{3}|[0-9a-f]{6})$/iFull-string validation.
Edge cases
- Rejects 4- and 8-digit forms with alpha (
#abcd,#11223344), which CSS Color Level 4 allows. Add|[0-9a-f]{4}|[0-9a-f]{8}if you need them.
2 required values still a placeholder; the assistant will ask for them.
details
- kind
- Prompt: a task you run by name to get one finished thing back
- domain
- Software engineering
- category
- Implementation
- level
- Intermediate
- made for
- Software engineer, Data engineer, Data analyst
- risk
- read-only
- version
- v1.0.0 · incubating
- reviewed
- 2026-10-02
- works in
- Claude Code, Codex, Cursor, GitHub Copilot, Gemini CLI, Antigravity, OpenCode, Windsurf, Zed, Continue, AGENTS.md, ChatGPT, claude.ai
use in
npx @hermes-hq/hodios install write-regex --target claude-codenpx skills add hermes-hq/hodios-dist --skill write-regex -a claude-codeclaude plugin marketplace add hermes-hq/hodios-distclaude plugin install hodios-software-engineering@hodiosThe plugin brings every entry in this domain at once.
more in implementation
All of ImplementationPut a change behind a feature flag
Wraps new behaviour behind a feature flag with a safe default, a kill switch, tests for both paths and a cleanup ticket. Use when shipping a risky change incrementally.
add-feature-flagAdd rate limiting to an API
Adds rate limiting to API endpoints with a fitting algorithm, keys, per-tier limits, standard headers, 429 responses and tests. Use when protecting endpoints from abuse or overload.
add-rate-limitingBackend engineer
Acts as a backend engineer focused on correct data handling, clear API contracts, explicit failure modes and services that are easy to operate. Use as a builder or reviewer persona for server code.
backend-engineerBuild a REST endpoint end to end
Implements one HTTP endpoint with route, input validation, handler, error mapping and tests in the project's own framework and conventions. Use when adding an API route.
build-rest-endpointBuild a reusable UI component
Builds a typed, accessible UI component from a description or screenshot, with loading, empty and error states and a usage example. Use when adding a component to a frontend.
build-ui-componentBuild a webhook handler
Implements a webhook receiver with signature checks, replay protection, idempotent processing, fast acknowledgement, async work, retries and tests. Use when integrating Stripe, GitHub or similar.
build-webhook-handler