XML Schema (XSD) 1.0 xs:pattern regex to match 4 digits as a string?

笑着哭i 提交于 2019-12-06 15:06:25

问题


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:


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'))"/>


来源:https://stackoverflow.com/questions/43871700/xml-schema-xsd-1-0-xspattern-regex-to-match-4-digits-as-a-string

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!