using System;
using System.Text.RegularExpressions;
public class Example
{
public static void Main()
{
string pattern = @"^ # 匹配行首
(?=.*[A-Z]) # 向前环视,匹配到大写字母
(?=.*[a-z]) # 向前环视,匹配到小写字母
(?=.*\d) # 向前环视,匹配到数字
(?=.*[_\W]) # 向前环视,匹配到特殊字符
.{10,} # 若满足以上环视条件,且有10个以上字符,则进行匹配
$ # 匹配行尾";
string input = @"// Good Case
asdfsadfANVasdfasdfasdf..sadfs1
www.baidu.com.COM123
qwerTYUIOP1233333333333333
qwerTYUIOP1233333333333333-=+
asdfsafxxxSSS..123
abcABC123,./
// Bad Case
xxxyyyzzz
XYZxyz123
aaabbbccc
12342353125123asedf";
RegexOptions options = RegexOptions.Multiline | RegexOptions.IgnorePatternWhitespace;
foreach (Match m in Regex.Matches(input, pattern, options))
{
Console.WriteLine("'{0}' found at index {1}.", m.Value, m.Index);
}
}
}
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 C#, please visit: https://msdn.microsoft.com/en-us/library/system.text.regularexpressions.regex(v=vs.110).aspx