111,125
社区成员
发帖
与我相关
我的任务
分享
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.IO;
namespace sxLdfang
{
class Program
{
static void Main(string[] args)
{
string html = @"23423G 678
";
string pattern = @"^[^A-Za-z]*[A-Za-z][^A-Za-z]*$";
MatchCollection mc = Regex.Matches(html, pattern);
foreach (Match m in mc)
{
Console.WriteLine(m.Value);
}
Console.ReadKey();
}
}
}
运行结果:
23423G 678
^[^a-zA-Z]*?[a-zA-Z][^a-zA-Z]*?$
void Main()
{
List<string>list=new List<string>
{
"23423a",
"B48349",
"324c434d",
"3498_ c-99"
};
foreach(string str in list)
{
Console.WriteLine("{0}:\t{1}",str,Check(str));
}
/*
23423a: True
B48349: True
324c434d: False
3498_ c-99: True
*/
}
bool Check(string str)
{
return Regex.Matches(str,"[a-zA-Z]").Count ==1;
}