我需要一个正则表达式,它将显示一个字符串以一个字符(az)开头,并且后跟至少一个数字。
我努力了...
^[a-zA-Z]{1}\d+
我的测试数据是...
a1234 (pass)
B123444434 (pass)
Z098745 (pass)
ZZ12345 (fail)
G4b553b3 (fail)
问题是最后两行应该失败但不要,我不确定问题是我的正则表达式还是我的 c#(下);
int pass = 0;
int fail = 0;
string[] testdata =
{
"a1234",
"B1234",
"Z098745",
"ZZ12345",
"G4b5533",
};
string sPattern = "[a-zA-Z]{1}\\d+";
foreach (string s in testdata)
{
if (System.Text.RegularExpressions.Regex.IsMatch(s, sPattern))
{
pass++;
}
else
{
fail++;
}
}