XML 正则表达式 - 否定匹配 [英] XML Regex - Negative match
问题描述
我在 XSD 模式中遇到了负前瞻问题.当我指定时:
I have a problem with negative lookahead in XSD pattern. When I specified:
<xs:pattern value="^(?!(00|\+\d))\d{6,}$"/>
然后我收到一条错误消息:
then I got an error message:
Value '^(?!(00|\+\d))\d{6,}$' is not a valid XML regular expression.
知道为什么它不起作用吗?
Any idea why it does not work?
在在线 javascript 验证器中它工作正常(例如 here 在单元测试部分点击 "运行测试").
In online javascript validator it works fine (e.g. here under unit tests section click on "run test").
我需要验证电话号码.电话号码不能包含国际前缀 (+\d) 和 (00).
I need to validate phone numbers. The phone number cannot include international prefixes (+\d) and (00).
谢谢
推荐答案
试试下面的正则表达式:
Try the following regex:
[1-9][0-9]{5,} | 0[1-9][0-9]{4,}
这匹配一个不以零开头且后跟任何数字(包括零)5次或更多次的数字,并且它还匹配一个以零开头并且是的数字不是后紧跟零,但之后可以有 0-9.
This matches a number which does not begin with zero and is followed by any digit (including zero) 5 or more times, and it also matches a number which starts with zero and is not immediately followed by zero, but after that can have 0-9.
这篇关于XML 正则表达式 - 否定匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!