// 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)^\d*?(?<first>(?<a>\d)\k<a>)\d*?(?!\k<first>)(?<second>(?<b>\d)\k<b>)\d*$").unwrap();
let string = "What should match (where # is just any digit, matching 1 or 2 or not)
11722
11227
71122
What should not match
11711
22227
88888
11x22
1122x
x1122
";
// 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/