pretty_regex

Crates.iopretty_regex
lib.rspretty_regex
version1.0.5
sourcesrc
created_at2023-08-09 04:11:08.299623
updated_at2023-12-03 11:37:03.724939
description🧶 Elegant and readable way of writing regular expressions
homepage
repositoryhttps://github.com/abs0luty/pretty_regex
max_upload_size
id939754
size40,001
Adi Salimgereev (abs0luty)

documentation

https://docs.rs/pretty_regex

README

🔮 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"));
Commit count: 27

cargo fmt