TL;DR — Quick Summary

grex generates regular expressions from test strings. Give it examples, get a regex back — no more hand-crafting complex patterns. Supports character classes, repetition, and anchoring.

grex writes regex for you. Give it example strings, get a pattern back — no more regex headaches.

Installation

# macOS
brew install grex

# Arch Linux
sudo pacman -S grex

# Cargo
cargo install grex

Usage

# Basic: generate regex from examples
grex 'hello' 'hallo' 'hullo'
# Output: ^h[aeu]llo$

# Digit class detection
grex --digits '2024-01-15' '2025-12-31' '2026-06-20'
# Output: ^\d{4}-\d{2}-\d{2}$

# Word class detection
grex --words 'cat' 'dog' 'fox'
# Output: ^\w{3}$

# Space class detection
grex --spaces 'hello world' 'foo bar'

# Repetitions
grex --repetitions 'aab' 'aaab' 'aaaab'
# Output: ^a{2,4}b$

# Case insensitive
grex --case-insensitive 'Hello' 'HELLO' 'hello'

# Non-capturing groups
grex --non-capturing-groups 'abc' 'def'

# Combine flags
grex --digits --words --repetitions '192.168.1.1' '10.0.0.1'

# From file (one string per line)
cat examples.txt | grex

# Verbose output
grex --verbose 'test1' 'test2' 'test3'

Summary

  • grex generates regular expressions from example strings automatically
  • Character class detection: digits, words, spaces
  • Repetition detection for quantity patterns
  • Unicode support for non-ASCII text
  • Written in Rust — also available as a library for programmatic use