C#正则表达式字符串必须至少有一个数字

时间:2018-04-19 10:29:23

标签: c#

如何将这两者结合起来,以便我的字符串只匹配至少一个大字母和至少一个数字

return Regex.IsMatch(string, 
                @"\A(?=\P{Lu}*\p{Lu})(?=\P{Ll}*\p{Ll})\p{L}+\z"); 
//but this works only with Big and small Letter, i dont know how I include the numbers

"^[0-9]+$" //Numbers

@"\A(?=\P{Lu}*\p{Lu})(?=\P{Ll}*\p{Ll})\p{L}+\z") 
//Letters which must receive at least one large

1 个答案:

答案 0 :(得分:0)

略微改编自另一个答案:(?=.*[0-9])(?=.*[A-Z])([A-Z0-9]+)

Fiddle with this on Regex101check the related answer