expression
Regex::new: compile a pattern
A regular expression describes a set of text patterns. Compilation checks the pattern syntax and prepares it for searching. An invalid pattern returns an error. This example uses the external regex crate; see the staged Cargo manifest. Expected stdout (not executed): true true Common mistake: Unwrapping patterns supplied by users.
Formal Syntax & Structure
rust syntaxrust
Regex::new(pattern) -> Result<Regex, Error>Working Example
Example Snippetrust
fn main() { let re = regex::Regex::new(r"[0-9]+").unwrap(); println!("{} {}", re.is_match("item 7"), regex::Regex::new("[").is_err());}