I have some trouble checking a string in XML for a specific schema. Everything works fine, but the string can contain a "/" Slash which is messing up my regular expression. The expression works fine except for the slash. I tried escaping the slash, but this is not working. The error says, that the pattern would not be a valid regular expression.
Thanks for your help.
<xs:simpleType name="idType">
<xs:restriction base="xs:string">
<xs:pattern value="[a-z\+A-Z\/0-9_-]*"/>
</xs:restriction>
</xs:simpleType>
You do not need to overescape the pattern, use
<xs:pattern value="[a-zA-Z0-9+/_-]*"/>
XSD regex patterns are specified using strings, not regex literals (as is usually the case in JavaScript/Ruby/PHP), without regex delimiters. /
is not a special regex metacharacter, and thus should not be escaped.
Actually, +
does not have to be escaped either inside a character class, and the hyphen, when placed at the end/start of the character class, does not have to be escaped either.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments