LinuxCommandLibrary
GitHubF-DroidGoogle Play Store

grex

Regex generator from example strings

TLDR

Generate regex from examples
$ grex [foo] [bar] [baz]
copy
Convert digits to `\d`
$ grex -d [test1] [test2]
copy
Convert whitespace to `\s` and words to `\w`
$ grex -s -w [example1] [example2]
copy
Case insensitive matching
$ grex -i [example1] [example2]
copy
Generate without start/end anchors
$ grex --no-anchors [examples...]
copy
Read examples from file (one per line)
$ grex -f [examples.txt]
copy

SYNOPSIS

grex [options] test-strings

DESCRIPTION

grex generates regular expressions from user-provided test strings. It analyzes the input examples and produces a regex that matches all of them. By default, the generated regex includes ^ and $ anchors.
The tool supports various character class conversions (\d, \s, \w and their inverses), repetition detection, and case-insensitive matching. It is useful for quickly creating regexes without manual pattern analysis.

PARAMETERS

TEST-STRINGS

Example strings to generate regex from.
-d, --digits
Convert Unicode decimal digits to \d.
-D, --non-digits
Convert non-digit characters to \D.
-s, --spaces
Convert Unicode whitespace to \s.
-S, --non-spaces
Convert non-whitespace characters to \S.
-w, --words
Convert Unicode word characters to \w.
-W, --non-words
Convert non-word characters to \W.
-i, --ignore-case
Generate case-insensitive regex.
-e, --escape
Replace all non-ASCII characters with unicode escape sequences.
-r, --repetitions
Detect repeated substrings and convert to quantifier notation.
--no-anchors
Remove ^ and $ anchors (anchors are added by default).
-f, --file FILE
Read test strings from a file (one per line).
-o, --output FILE
Write generated regex to a file.
--help
Display help information.

CAVEATS

Generated regex may be overly specific or general. Manual refinement often needed. Complex patterns may require additional examples.

HISTORY

grex was created by Peter M. Stahl as a command-line tool to simplify regex creation through example-based learning.

SEE ALSO

grep(1), sed(1), regex(7)

Copied to clipboard
Kai