XML Schema (XSD) 1.0 xs:pattern regex to match 4 d

2019-04-16 20:02发布

How can I match a specific sequence of digits as if it were a string in an XML Schema xs:pattern?

Say I have some tags containing arbitrary 10-character strings like

<string>12345678990</string>

And I want to rule out all tags with a specific blacklist of arbitrary sequences like 1234, 2435, ``9587`, or some such.

How do I address the specific 4-digit sub-string in order to negate it and add it to a list of xs:pattern restrictions for <string>'s content model?

1条回答
啃猪蹄的小仙女
2楼-- · 2019-04-16 20:10

I don't think there is any practical XSD-compliant regular expression that will match all strings except those containing "1234" as a substring. (And therefore your more challenging requirement of banning several substrings also cannot be met).

This is one for XSD 1.1 assertions, for example

<xs:assert test="not(contains($value, '1234') or contains($value, '9999'))"/>
查看更多
登录 后发表回答