Expand description
§🔮 Write readable regular expressions
The crate provides a clean and readable way of writing your regex in the Rust programming language:
Without |
With |
|
ⓘ
|
|
ⓘ
|
|
ⓘ
|
§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"));
Modules§
Structs§
- Ascii
- Represents the state when regular expression is for a single-character ASCII class (the kind surrounded by colons and two layers of square brackets).
- Chain
- Represents the state when it is any arbitrary regular expression.
- Char
Class - Represents the state when regular expression corresponds to a single-character character.
- Custom
- Represents the state when regular expression is for a custom single-character class (the kind surrounded by one layer of square brackets).
- Pretty
Regex - Quantifier
- Represents the state when regular expression is a quantifier (e.g., an expression that matches a given number of a target).
- Standard
- Represents the state when regular expression is a standard single-character class (the kind in most cases starts with a backslash followed by a letter)
- Text
- Represents the state when regular expression is a literal string of characters.
Functions§
- alphabetic
- Matches alphabetic characters (in
Letter
Unicode category). - alphanumeric
- Matches alphanumeric characters (in
Letter
andNumber
Unicode categories). - any
- Matches any character, except for newline (
\n
). - ascii_
alphabetic - Matches ascii alphabetic characters (
a-zA-Z
). - ascii_
alphanumeric - Matches ascii alphanumeric characters (
a-zA-Z0-9
). - ascii_
lowercase - Matches ascii lowercase characters (
a-z
). - beginning
- Matches the beginning of the text or SOF with multi-line mode off (
^
). - digit
- Matches digit character class (
\d
). - ending
- Matches the end of the text or EOF with multi-line mode on (
$
). - just
- Adds a matching text into a
PrettyRegex
. - lowercase
- Matches lowercase characters (in
Lowercase_Letter
Unicode category). - nonescaped
- Makes regex from unescaped text. It allows to add a regex string directly into a
PrettyRegex
object. - one_of
- Establishes an OR relationship between regular expressions.
- text_
beginning - Matches the beginning of the text even with multi-line mode on (
\A
). - text_
ending - Matches the end of the text even with multi-line mode on (
\z
). - whitespace
- Matches whitespace character class (
\s
). - within
- Matches anything within a specified set of characters.
- within_
char_ range - Matches characters within a given range.
- without
- Matches anything outside of a specified set of characters.
- without_
char_ range - Matches characters outside of a given range.
- word
- Matches word character class (
\w
) - any alphanumeric character or underscore (_
). - word_
boundary - Matches a word boundary (
\b
).