开发者

Regex for: Must contain a numeric, excluding "SomeText1"

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]+.*$
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜