// 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)^ # 匹配行首
(?=.*[A-Z]) # 向前环视,匹配到大写字母
(?=.*[a-z]) # 向前环视,匹配到小写字母
(?=.*\d) # 向前环视,匹配到数字
(?=.*[_\W]) # 向前环视,匹配到特殊字符
.{10,} # 若满足以上环视条件,且有10个以上字符,则进行匹配
$ # 匹配行尾").unwrap();
let string = "// Good Case
asdfsadfANVasdfasdfasdf..sadfs1
www.baidu.com.COM123
qwerTYUIOP1233333333333333
qwerTYUIOP1233333333333333-=+
asdfsafxxxSSS..123
abcABC123,./
// Bad Case
xxxyyyzzz
XYZxyz123
aaabbbccc
12342353125123asedf";
// 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/