← Back to tools

grex

Generate regular expressions from user-provided test cases

Text Processing Development linuxmacoswindows Rust Apache-2.0

Description

grex is a command-line tool that generates regular expressions from provided test strings. It creates the smallest possible regex that matches all given inputs, with options for character classes, repetitions, and anchoring.

Install

homebrewbrew install grex
cargocargo install grex

AI Summary

A regex generator from test cases. Provide example strings and grex creates the smallest regular expression that matches all of them.

Capabilities

  • + Generates regex from positive test cases
  • + Supports digit, word, and whitespace character classes
  • + Configurable repetition and anchoring
  • + Outputs regex compatible with most regex engines

Use When

  • Need to create a regex matching a set of example strings
  • Want a starting point for a regex pattern
  • Unfamiliar with regex syntax

Avoid When

  • x Need a regex for complex patterns with negative cases
  • x Regex must handle edge cases beyond the examples provided

Usage Patterns

Generate regex from examples

grex 'foo-123' 'bar-456' 'baz-789'

Generates a regex matching all three strings

Use digit character classes

grex -d 'abc-123' 'def-456'

Uses \d instead of [0-9] in the generated regex

Input / Output

stdout: Generated regular expression
Exit codes:
0 Success
1 Error
View AGENTS.md for grex