grex is a library as well as a command-line utility that is meant to simplify the often complicated and tedious task of creating regular expressions. It does so by automatically generating a single regular expression from user-provided test cases. The resulting expression is guaranteed to match the test cases which it was generated from.
The philosophy of this project is to generate the most specific regular expression possible by default which exactly matches the given input only and nothing else. With the use of command-line flags (in the CLI tool) or preprocessing methods (in the library), more generalized expressions can be created.
The produced expressions are Perl-compatible regular expressions which are also compatible with the regular expression parser in Rust’s regex crate. Other regular expression parsers or respective libraries from other programming languages have not been tested so far, but they ought to be mostly compatible as well.
This is free and open source software.
Features include:
- Literals.
- Character classes.
- Detection of common prefixes and suffixes.
- Detection of repeated substrings and conversion to {min,max} quantifier notation.
- Alternation using | operator.
- Optionality using ? quantifier.
- Escaping of non-ascii characters, with optional conversion of astral code points to surrogate pairs.
- Case-sensitive or case-insensitive matching.
- Capturing or non-capturing groups.
- Optional anchors ^ and $.
- Fully compliant to Unicode Standard 15.0.
- Fully compatible with regex crate 1.9.0+.
- Correctly handles graphemes consisting of multiple Unicode symbols.
- Reads input strings from the command-line or from a file.
- Produces more readable expressions indented on multiple using optional verbose mode.
- Optional syntax highlighting for nicer output in supported terminals.
Digit Options:
-d
, --digits
Converts any Unicode decimal digit to \d
-D
, --non-digits
Converts any character which is not a Unicode decimal digit to \D
Whitespace Options:
-s
, --spaces
Converts any Unicode whitespace character to \s
-S
, --non-spaces
Converts any character which is not a Unicode whitespace character to \S
Word Options:
-w
, --words
Converts any Unicode word character to \w
-W
, --non-words
Converts any character which is not a Unicode word character to \W
Escaping Options:
-e
, --escape
Replaces all non-ASCII characters with unicode escape sequences
--with-surrogates
Converts astral code points to surrogate pairs if –escape is set
Repetition Options:
-r
, --repetitions
Detects repeated non-overlapping substrings and converts them to {min,max} quantifier
notation
--min-repetitions
Specifies the minimum quantity of substring repetitions to be converted if –repetitions
is set [default: 1]
--min-substring-length
Specifies the minimum length a repeated substring must have in order to be converted if
--repetitions
is set [default: 1]
Anchor Options:
--no-start-anchor
Removes the caret anchor `^` from the resulting regular expression
--no-end-anchor
Removes the dollar sign anchor `$` from the resulting regular expression
--no-anchors
Removes the caret and dollar sign anchors from the resulting regular
expression
Display Options:
-x
, --verbose
Produces a nicer-looking regular expression in verbose mode
-c
, --colorize
Provides syntax highlighting for the resulting regular expression
Miscellaneous Options:
-i
, --ignore-case
Performs case-insensitive matching, letters match both upper and lower case
-g
, --capture-groups
Replaces non-capturing groups with capturing ones
-h
, --help
Prints help information
-v
, --version
Prints version information
Website: github.com/pemistahl/grex
Support:
Developer: Peter M. Stahl
License: Apache License 2.0
grex is written in Rust. Learn Rust with our recommended free books and free tutorials.
Popular series | |
---|---|
![]() | The largest compilation of the best free and open source software in the universe. Each article is supplied with a legendary ratings chart helping you to make informed decisions. |
![]() | Hundreds of in-depth reviews offering our unbiased and expert opinion on software. We offer helpful and impartial information. |
![]() | The Big List of Active Linux Distros is a large compilation of actively developed Linux distributions. |
![]() | Replace proprietary software with open source alternatives: Google, Microsoft, Apple, Adobe, IBM, Autodesk, Oracle, Atlassian, Corel, Cisco, Intuit, and SAS. |
![]() | Awesome Free Linux Games Tools showcases a series of tools that making gaming on Linux a more pleasurable experience. This is a new series. |
![]() | Machine Learning explores practical applications of machine learning and deep learning from a Linux perspective. We've written reviews of more than 40 self-hosted apps. All are free and open source. |
![]() | New to Linux? Read our Linux for Starters series. We start right at the basics and teach you everything you need to know to get started with Linux. |
![]() | Alternatives to popular CLI tools showcases essential tools that are modern replacements for core Linux utilities. |
![]() | Essential Linux system tools focuses on small, indispensable utilities, useful for system administrators as well as regular users. |
![]() | Linux utilities to maximise your productivity. Small, indispensable tools, useful for anyone running a Linux machine. |
![]() | Surveys popular streaming services from a Linux perspective: Amazon Music Unlimited, Myuzi, Spotify, Deezer, Tidal. |
![]() | Saving Money with Linux looks at how you can reduce your energy bills running Linux. |
![]() | Home computers became commonplace in the 1980s. Emulate home computers including the Commodore 64, Amiga, Atari ST, ZX81, Amstrad CPC, and ZX Spectrum. |
![]() | Now and Then examines how promising open source software fared over the years. It can be a bumpy ride. |
![]() | Linux at Home looks at a range of home activities where Linux can play its part, making the most of our time at home, keeping active and engaged. |
![]() | Linux Candy reveals the lighter side of Linux. Have some fun and escape from the daily drudgery. |
![]() | Getting Started with Docker helps you master Docker, a set of platform as a service products that delivers software in packages called containers. |
![]() | Best Free Android Apps. We showcase free Android apps that are definitely worth downloading. There's a strict eligibility criteria for inclusion in this series. |
![]() | These best free books accelerate your learning of every programming language. Learn a new language today! |
![]() | These free tutorials offer the perfect tonic to our free programming books series. |
![]() | Linux Around The World showcases usergroups that are relevant to Linux enthusiasts. Great ways to meet up with fellow enthusiasts. |
![]() | Stars and Stripes is an occasional series looking at the impact of Linux in the USA. |