> module
std::regex
regular expressions
std::regex provides regular expressions using the Rust regex crate's syntax: Perl-like, but without look-around or backreferences, and matching in linear time. Matching works on Unicode text.
> functions
> types
A regex error. The pattern failed to compile; the message says why. Match it as `Err(regex::Error::Invalid(msg))`.
| Error::Invalid(str) |
The groups of the first match: item 0 is the whole match, then one item per group, with None for a group that didn't take part. Returns None if there is no match.
Replaces the first match, or every match. In replacement, $1 or ${name} inserts a group and $$ a literal $.
Replaces the first match, or every match. In replacement, $1 or ${name} inserts a group and $$ a literal $.
> errors
regex::Error has one variant, Invalid(str), with the compiler's message.
> examples
use std::regex;
use std::io;
fn main() -> Result<()> {
let re = regex::new("\\d+")?;
io::println("{}", re.find_all("a1 b22 c333"));
// => ["1", "22", "333"]
let email = regex::new("(\\w+)@(\\w+\\.\\w+)")?;
match email.captures("user@example.com") {
Some(caps) => io::println("{} at {}", caps[1].unwrap(), caps[2].unwrap()),
None => io::println("no match"),
}
Ok(())
}