I need a regex pattern (must be a single pattern) to match any text that contains a number, excluding a specific literal (i.e. "SomeTe开发者_JAVA百科xt1").
I have the match any text containing a number part:
^.*[0-9]+.*$
But am having a problem excluding a specific literal.
Update: This is for .NET Regex.
Thanks in advance.
As a verbose 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
If your regex flavor doesn't support those:
^(?=.*[0-9])(?!SomeText1$).*$
Use negative-look-ahead:
^(?!.*?SomeText1).*?[0-9]+.*$
精彩评论