如何在c#中查找给定字符串是否包含至少一个数字后跟字母表使用正则表达式?
例如:
var strInput="Test123Test";
该函数应返回bool值。
答案 0 :(得分:3)
result = Regex.IsMatch(subjectString, @"\d\p{L}");
将为您的示例字符串返回True
。目前,此正则表达式还将非ASCII数字和字母视为有效匹配,如果您不希望这样,请改用@"[0-9][A-Za-z])"
。
答案 1 :(得分:0)
如果您只想匹配123: -
Match m = Regex.Match("Test123Test", @"(\p{L}+)(\d+)") ;
string result = m.Groups[2].Value
如果您想获得bool值,请执行以下操作: -
Console.WriteLine(!String.IsNullOrEmtpty(result))) ;
或简单使用: -
Regex.IsMatch("Test123Test", @"\p{L}+\d+") ;
答案 2 :(得分:0)
试试这个:
if(Regex.IsMatch(strInput, @"[0-9][A-Za-z]"))
...