我需要一个正则表达式模式(必须是单一模式)来匹配任何包含数字的文本,不包括特定文字(即“SomeText1”)。
我匹配任何包含数字部分的文本:
^.*[0-9]+.*$
但是我在排除特定文字时遇到了问题。
更新:这是针对 .NET Regex 的。
提前致谢。
请您参考如下方法:
作为冗长的正则表达式:
^ # Start of string
(?=.*[0-9]) # Assert presence of at least one digit
(?!SomeText1$) # Assert that the string is not "SomeText1"
.* # If so, then match any characters
$ # until the end of the string
如果您的正则表达式风格不支持这些:
^(?=.*[0-9])(?!SomeText1$).*$
