问题
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