Is this supposed to work?
When i use
<xs:pattern value="(!red|green|blue)"/>
everything is fine, but using:
<xs:pattern value="(?!red|green|blue)"/>
(notice the added “?”)
EDIT: found this in another SO question, it doesnt work either:
^((?!red|green|blue)|((red|green|blue).+)).*$
Both causes:
/home/asdf/.rvm/gems/ruby-1.9.3-p125@tretti_order/gems/nokogiri-1.5.2/lib/nokogiri/xml/schema.rb:37:in `from_document': Element '{http://www.w3.org/2001/XMLSchema}pattern': The value '(?!red|green|blue' of the facet 'pattern' is not a valid regular expression. (Nokogiri::XML::SyntaxError)
from /home/asdf/.rvm/gems/ruby-1.9.3-p125@tretti_order/gems/nokogiri-1.5.2/lib/nokogiri/xml/schema.rb:37:in `new'
from /home/asdf/.rvm/gems/ruby-1.9.3-p125@tretti_order/gems/nokogiri-1.5.2/lib/nokogiri/xml/schema.rb:8:in `Schema'
from xml_validate.rb:12:in `<main>'
Context:
<xs:simpleType name="attributeIdType">
<xs:annotation>
<xs:appinfo>Attribute Id Type.</xs:appinfo>
<xs:documentation source="http://www.web3d.org/x3d/specifications/ISO-IEC-19775-1.2-X3D-AbstractSpecification/Part01/fieldsDef.html#SFDouble"/>
</xs:annotation>
<xs:restriction base="xs:string">
<xs:whiteSpace value="collapse"/>
<xs:pattern value="(?!red|green|blue)"/>
</xs:restriction>
</xs:simpleType>
What you have with
(?!foo)is called a “zero-width negative lookahead assertion”; it says “Make sure that, standing at this spot and looking forward, you cannot match this pattern.”According to this page XML Schema’s
patterndoes not support lookarounds of any sort (positive or negative, forward or backward).However, since you say, “The purpose is to make sure that if a string starts with
ABC_PRODUCT_it only ends with a certain string.” you don’t need a lookaround. You can simply do this:This will match “foo”, “bar_jim” and “bar_jam”, but not “bar_zzz”.