这样能行吗?
当我用
<xs:pattern value="(!red|green|blue)"/>一切都很好,但是使用:
<xs:pattern value="(?!red|green|blue)"/>(请注意添加的"?")
编辑:在另一个问题中发现了这一点,所以它也不起作用,
^((?!red|green|blue)|((red|green|blue).+)).*$这两个原因都是:
/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>'上下文:
<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>发布于 2012-04-23 16:25:45
您所拥有的(?!foo)称为“零宽度负前瞻性断言”;它说:“请确保站在这个位置并展望未来,您无法匹配此模式。”
根据此页,XML的pattern不支持任何类型的外观(正或负,向前或向后)。
但是,既然您说,“目的是确保如果一个字符串以`ABC_PRODUCT`_开头,它只以某个字符串结尾。”你不需要环顾四周。您可以简单地这样做:
pattern="(foo|bar_(jim|jam)"这将匹配"foo“、"bar_jim”和"bar_jam",而不是"bar_zzz“。
https://stackoverflow.com/questions/10278162
复制相似问题