Reputation: 15513
I need a regex pattern (must be a single pattern) to match any text that contains a number, excluding a specific literal (i.e. "SomeText1").
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.
Upvotes: 1
Views: 514
Reputation: 336328
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$).*$
Upvotes: 5