#regex #human-readable #regular #regexpr

pretty_regex

🧶 Elegant and readable way of writing regular expressions

9 releases (stable)

1.0.5 Dec 3, 2023
1.0.4 Sep 9, 2023
1.0.2 Aug 9, 2023
0.1.2 Aug 9, 2023

#80 in Value formatting

Download history 352/week @ 2024-02-26 3/week @ 2024-03-11 87/week @ 2024-04-01

90 downloads per month

MIT license

39KB
577 lines

🔮 Write readable regular expressions

The crate provides a clean and readable way of writing your regex in the Rust programming language:

Without pretty_regex

With pretty_regex

\d{5}(-\d{4})?
digit() * 5 + (just("-") + digit() * 4).optional()
^(?:\d){4}(?:(?:\-)(?:\d){2}){2}$
beginning() + digit() * 4
            + (just("-") + digit() * 2) * 2
            + ending()
rege(x(es)?|xps?)
just("rege") + (just("x") + just("es").optional())
             | (just("xp") + just("s").optional())

How to use the crate?

To convert a PrettyRegex into a regex from regex crate, you can call to_regex or to_regex_or_panic:

use pretty_regex::digit;

let regex = (digit() + ascii_alphabetic().optional()).to_regex_or_panic();

assert!(regex.is_match("3"));

Dependencies

~2–3MB
~53K SLoC