开发者

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

开发者 https://www.devze.com 2023-03-16 19:19 出处:网络
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 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

精彩评论

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