pretty_regex 1.0.2

🧶 Elegant and readable way of writing regular expressions
Documentation

🔮 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()
  .repeats(5)
  .then(
    just("-")
     .then(digit().repeats(4))
     .optional()
  )
^(?:\d){4}(?:(?:\-)(?:\d){2}){2}$
beginning()
  .then(digit().repeats(4))
  .then(
    just("-")
      .then(digit().repeats(2))
      .repeats(2)
  )
  .then(ending())
rege(x(es)?|xps?)
just("rege")
  .then(one_of(&[
    just("x").then(just("es").optional()),
    just("xp").then(just("s").optional()),
  ]))

How to use the crate?

To convert a PrettyRegex struct which is constructed using all these then, one_of, beginning, digit, etc. functions into a real regex (from regex crate), you can call to_regex or to_regex_or_panic:

use pretty_regex::digit;

let regex = digit().to_regex_or_panic();

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