Favicon of grex

grex

Automatically create regular expressions from sample inputs. Detects patterns, handles Unicode, and supports case-insensitive matching with optional optimization flags.

grex automatically generates regular expressions from test cases you provide, eliminating the need to manually construct complex patterns. Simply supply example strings that should match, and the tool produces a single regex guaranteed to match those inputs.

The tool excels at detecting common patterns like repeated substrings, shared prefixes and suffixes, and character class opportunities. It handles Unicode characters seamlessly, including non-ASCII text and astral code points, with optional conversion to surrogate pairs. You can choose between case-sensitive or case-insensitive matching, use capturing or non-capturing groups, and add anchors as needed.

Key capabilities include:

  • Automatic pattern detection and optimization
  • Character class generation and shorthand conversion
  • Quantifier notation for repeated elements
  • Alternation and optional matching
  • Unicode Standard 16.0 compliance
  • Verbose mode for readable multi-line output
  • Syntax highlighting in supported terminals
  • File input support for batch processing

Important note: While grex produces correct initial expressions, manual inspection and refinement is often beneficial. The generated regex matches your test cases precisely but may be longer than hand-optimized versions. Understanding regex fundamentals helps you evaluate and improve the output for your specific use case. Available as both a command-line tool and Rust library, grex works across Linux, macOS, and Windows platforms.

Install

Pip
$ pip install grex
Pip
$ pip install maturin

Media

Pros

4
  • Automatically generates regex from sample inputs
  • Supports Unicode and case-insensitive matching
  • Generates Perl-compatible regular expressions
  • Offers a library and command-line utility

Cons

2
  • Generated regex may be longer or more complex than manually written ones
  • Does not optimize for specific regex engines

Related tools

Share:

Auto-fetched .

Recent releases

Similar to grex

Favicon

 

  
 
Favicon

 

  
 
Favicon