Macro rust_regex_dsl::regex
source · regex!() { /* proc-macro */ }
Expand description
A simple regular expression macro.
This macro will validate the regular expression and will produce a compile time error if the expression
is invalid. This can allow a developer to know that the hard coded regular expressions are valid. The result will be a valid [regex::Regex
].
For example:
use rust_regex_dsl::regex;
use regex::Regex;
use lazy_static::lazy_static;
lazy_static! {
static ref VALID_NAME: Regex = regex!("[a-z][a-zA-Z_]*");
}
Is equivalent to:
use rust_regex_dsl::regex;
use regex::Regex;
use lazy_static::lazy_static;
lazy_static! {
static ref VALID_NAME: Regex = Regex::new("[a-z][a-zA-Z_]*").unwrap();
}
But this:
ⓘ
use rust_regex_dsl::regex;
use regex::Regex;
use lazy_static::lazy_static;
lazy_static! {
static ref VALID_NAME: Regex = regex!("[a-z][a-zA-Z_*");
}
will fail with compilation error (because of the missing closing square bracket) while using the same without the macro will fail in run time.