// include the latest version of the regex crate in your Cargo.toml
extern crate regex;
use regex::Regex;
fn main() {
let regex = Regex::new(r"(?m)all").unwrap();
let string = "A regex with the character pattern \"all\", will match each occurrences of the letter a followed by two l letters in a text. This means it will find matches for all, hallway, ballon and fall.
The two l:s, needs to come after the letter a, so it will not match dollar or pillar. The regex also expects two l:s, one isn't enough. It will not find any match in words like falcon or although. If the text contains other characters in betwen the a and the two l:s, it won't consider it as a match. This means it won't find a match in the name Al Leaong or if we misspell all life as al life.";
// result will be an iterator over tuples containing the start and end indices for each match in the string
let result = regex.captures_iter(string);
for mat in result {
println!("{:?}", mat);
}
}
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for Rust, please visit: https://docs.rs/regex/latest/regex/