// 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)([\w ]+) (is friends with) ([\w ]+)
").unwrap();
let string = "Jesus is friends with Chuck Norris
Cindy Crawford is friends with Nicole Kidman
V is friends with Barack Obama
Chuck Norris is friends with Barack Obama
V is friends with François Hollande
Penelope Cruiz is friends with Tom Cruise
Nicole Kidman is friends with Tom Cruise
Katie Holmes is friends with Tom Cruise
Sim is friends with Lara Croft
Sim is friends with Chuck Norris
Lara Croft is friends with V
Yvette Horner is friends with Sim
François Hollande is friends with Barack Obama
Sim is friends with Jesus
Tom Cruise is friends with Barack Obama
";
// 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/