// 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"(?mi)(\bShe\b)(?:(?!\b(?:she|loves|you)\b).)*(\bloves\b)(?:(?!\b(?:she|loves|you)\b).)*(\byou\b)").unwrap();
let string = "My she baby loves loving, my baby loves loving She's got what it takes, and she knows how to use it My baby loves loving, my baby loves loving She's got what it takes, and she knows how to use it I was lonely once in this great big world Just a nowhere man without a girl 'Till that lucky day when she came my way And she smiled at me as if to say My baby loves loving, my baby loves loving She's got what it takes, and she knows how to use it My baby loves loving, my baby loves loving She's got what it takes, and she knows how to use it She's the only one, makes me feel so good Can't believe my love so I knock on wood All my silent fears seem to fly away And she smiled at me as if to say Your baby loves loving, my baby loves loving She's got what it takes for me No more lonely nights just waiting for the telephone to ring No more lonely days, my baby's taking care of everything I'm telling you people My baby loves loving, my baby loves loving She's got what it takes, and she knows how to use it My baby loves loving, my baby loves loving She's got what it takes, and she knows how to use it She's the only one, makes me feel so good Can't believe my love so I knock on wood All my silent fears seem to fly away And she looked at me as if to say";
// 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/