hermes

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.

context

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.

task

Write a regular expression for:

Must match:

Must not match:

  1. 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).
  2. Respect the engine:
  • javascript: use the u flag for Unicode; \d and \w are ASCII-only.
  • python: use re.fullmatch for validation, or \Z rather than $; in Python 3, \d and \w match Unicode unless you pass re.ASCII.
  • pcre: $ matches before a final newline; use \z for 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:]].
  1. Prefer the simplest pattern that passes every example. Avoid nested quantifiers over overlapping classes such as (a+)+ or (\w|\d)*.
  2. 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.
  3. 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.
  4. If the examples contradict the intent or each other, say which ones and which reading you followed.
constraints
  • 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.
output format

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).

examples
example

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})$/i

Full-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

Edit on GitHubReport a problem

use in

Hodios CLI
npx @hermes-hq/hodios install write-regex --target claude-code
Agent Skills
npx skills add hermes-hq/hodios-dist --skill write-regex -a claude-code
Add the Hodios marketplace (once)
claude plugin marketplace add hermes-hq/hodios-dist
Install the software-engineering plugin
claude plugin install hodios-software-engineering@hodios

The plugin brings every entry in this domain at once.

more in implementation

All of Implementation
PromptImplementation

Put 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-flag
PromptImplementation

Add 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-limiting
PersonaImplementation

Backend 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-engineer
PromptImplementation

Build 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-endpoint
PromptImplementation

Build 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-component
PromptImplementation

Build 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