← 返回命令列表

Linux command

grex 命令

文本

复制后可按需替换文件名、目录或参数。

常用示例

Generate regex from examples

grex [foo] [bar] [baz]

Convert digits to

grex -d [test1] [test2]

Convert whitespace to

grex -s -w [example1] [example2]

Case insensitive matching

grex -i [example1] [example2]

Generate with repetition detection

grex -r [aaab] [aaac]

Generate without start/end anchors

grex --no-anchors [examples...]

Read examples from file

grex -f [examples.txt]

说明

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.

参数

-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).
--no-start-anchor
Remove the ^ start anchor only.
--no-end-anchor
Remove the $ end anchor only.
-f, --file _FILE_
Read test strings from a file (one per line).
--help
Display help information.

FAQ

What is the grex command used for?

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.

How do I run a basic grex example?

Run `grex [foo] [bar] [baz]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.

What does -d, --digits do in grex?

Convert Unicode decimal digits to \d.