// 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"(?ux) \b
((?<CASE_UPPER>[[:upper:]]+)|
(?<CASE_INITIALCAPS>[A-Z][a-z]+[A-Z]*+)|
(?<CASE_MIXED>[A-z]*[A-Z][A-z]*+)|
(?<PHRASE>[A-Z][\w-]*(\s+[A-Z][\w-]*)+))
\b").unwrap();
let string = "I am testing to see if this works for UPPERCASE, InitialCase and mixedCase which of course is also mIxedcase. Firstword initial case should not be matched. FirstWordMixed case should be. UPPERCASE first word should be. And of course phrases that combine any combination of UPPER mixEd Initicase should be pulled as a phrase not a word which could be of course Initcase1 Initcase2 Initcase3. Finally it needs to match all sorto of Associations such as Association of First Words, Last Word for Association, Middle Word Association for Words.";
// 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/