Crates.io | regexnight |
lib.rs | regexnight |
version | 0.2.0 |
source | src |
created_at | 2024-11-21 13:37:39.091044 |
updated_at | 2024-12-10 10:43:55.550502 |
description | Command-line tool to print syntax-highlighted versions of regular expressions and spot errors |
homepage | |
repository | https://gitlab.com/agateau/regexnight |
max_upload_size | |
id | 1456124 |
size | 145,110 |
🎶 Regex night, we come together when the code ain't right
🎶 Regex night, and we'll be debuggin' 'til the morning light
Regex Night is a command-line tool to print syntax-highlighted versions of regular expressions and spot errors in them.
Regex Night main commands are:
print
: print a syntax-highlighted version of the regular expression. As a tree if --tree
is set.lint
: report errors found in a regular expression.Let's have a look at this regex used to match phone numbers:
^\+?(\d[\d-. ]+)?(\([\d-. ]+\))?[\d-. ]+\d$
(Source: https://www.variables.sh/complex-regular-expression-examples/)
regexnight print
can produce a colored version of it:
That's nice but still cryptic. We can get a more readable result with the --tree
option:
Regex Night can also be used to lint regular expressions. Here is a regular expression with an unnecessary extra group:
Hello (?P<name>(?:\w+))!
Running this expression through regexnight lint
gives us:
Each command lets you pass a regular expression either on the command-line, via a file or by reading it from stdin:
regexnight print '(foo|bar)'
echo '(foo|bar)' | regexnight print
echo '(foo|bar)' > a_file
regexnight print -f a_file
Passing a regular expression from the command-line is handy for simple regular expressions, but can get complicated when it includes quotes or backslashes as those have to be properly escaped for the shell to pass them unaltered. In these situations it's less error-prone to write the regular expression in a file or just run the command without argument and type in the regular expression.
If you have Rust installed, run:
cargo install regexnight
Install with Clyde:
clyde install regexnight
Or download the binary from the release page and put it in your PATH.
There are only x86-64 Linux binaries for now.
regexnight lint
found some problems