// 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"(?mx)^ # start of line
(?=(?:.*[A-Z]){2,}) # 2 upper case letters
(?=(?:.*[a-z]){2,}) # 2 lower case letters
(?=(?:.*\d){2,}) # 2 digits
(?=(?:.*[!@#$%^&*()\-_=+{};:,<.>]){2,}) # 2 special characters
(?!.*(.)\1{2}) # negative lookahead, dont allow more than 2 repeating characters
([A-Za-z0-9!@#$%^&*()\-_=+{};:,<.>]{12,20}) # length 12-20, only above char classes (disallow spaces)
$ # end of line
").unwrap();
let string = "kH8kDi3j)_hajw";
// 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/