I'm trying to use a regex to validate a field in my xml using xsd. I came up with the regex to do what I want which is to disallow special characters unless the text is wrapped in CDATA tags. This is the regular expression I came up with:
<!\[CDATA\[.*?\]\]>|[^<>&]*
Works great when I test it on http://regexr.com/ to match my pattern. The problem is when I try to then plug it into a simpleType pattern restriction I'm getting an error saying its not a valid regular expression.
The value '<!\[CDATA\[.*?\]\]>|[^<>&]*' of the facet 'pattern' is not a valid regular expression.
Here is my xsd code (note I had to replace &<> in the regular expression with <
>
and &
so it would be valid xml):
<xs:element name="description" minOccurs="1" maxOccurs="1">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:pattern value="<!\[CDATA\[.*?\]\]>|[^<>&]*"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
So I assume there's something about the way regex works in xsd patterns that I'm not getting.