Regex generation CLI that turns sample strings into a regular expression, with flags for anchors, character classes, and repetition handling.
$brew install grex
AI Analysis
grex is a CLI and library for generating a single regular expression from example strings. It is most useful for bootstrapping patterns from known test cases rather than hand-authoring or debugging full regex logic from scratch.
What It Enables
- Turn sample strings from arguments, stdin, or a file into one regex that matches those cases.
- Generalize the output with flags for word, digit, or whitespace classes, repeated substrings, case-insensitive matching, capture groups, and optional anchors.
- Emit readable or colorized regex text that can be pasted into code, config, tests, or follow-up shell commands.
Agent Fit
- Non-interactive flags plus stdin and file input make it straightforward to call from scripts when an agent needs a starter pattern.
- Output is plain regex text with no JSON schema, so follow-up automation depends on the agent already knowing where to insert or test that pattern.
- Best for narrow text-processing and code-generation steps, not for inspecting external systems or replacing regex review.
Caveats
- The project explicitly warns that generated regexes should still be inspected by hand and may need engine-specific simplification or tuning.
- Options such as
\w,\d,\s, or repetition conversion can widen matches beyond the original examples if used carelessly.