// 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)^(([^"']*?)foo(.*)|(.*?)foo([^"']*))$"#).unwrap();
let string = "hello foo
hello \"foo\" and foo not 'foo'
Hello \"foo\" foo, how are \"you\" doing?
they \"are foo and bar\" and foo
This foo \" is too a match
\"foo\" not bar but foo
This foo ' should be matched
Then foo said \"foo bar\", which didn't work
\"This is the foo bar\"
hello \"foo\"
hello \"foo\"
hello 'foo'
you said \"my name is foo\"
";
// 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/