[英]Need a regular expression - disallow only zeros, allow zeros with other numbers
I want to validate a string to meet the following patterns: 我想验证一个字符串以满足以下模式:
00;0 (disallow)
00;00 (disallow)
01;123 (disallow)
00;1
00; (disallow)
00;000000 (disallow)
00;1234567890123 (disallow)
00;123456789012
00;10
00;01
00;00001
00;00100
00;0202020
00;1000000
00;00100100
In general, the string should be ^00;\\d{1,12}$
but how to eliminate unnecessary lines in the example above and resolve the necessary in one regex expression? 通常,字符串应为^00;\\d{1,12}$
但是如何在上面的示例中消除不必要的行并在一个正则表达式中解析必要的行?
Thanks. 谢谢。
You may use this regex: 您可以使用此正则表达式:
^00;(?!0+$)\d{1,12}$
RegEx Details: 正则表达式详细信息:
^00;
: Match 00;
:比赛00;
at start of line 行首 (?!0+$)
: Negative lookahead to fail the match if we have all zeroes (?!0+$)
:如果我们全为零,则负向超前使匹配失败 \\d{1,12}$
: Match 1 to 12 characters of any digit before end \\d{1,12}$
:在末尾匹配1到12个任意数字的字符
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.