此正则表达式对xsd无效

时间:2015-05-25 22:49:05

标签: python regex xml xsd lxml

我想验证一个2或3个字母的iso代码,但也允许它为空(所以它可以是0,2或3个字符)。

'\w{2,3}|'

这适用于本地和http://www.freeformatter.com/xml-validator-xsd.html。但是,当我尝试在ubuntu机器上运行它时,我收到以下错误:

>>> import urllib2
>>> from lxml import etree
>>> xsd_url = 'https://s3-us-west-1.amazonaws.com/premiere-avails/movie.xsd.xml'
>>> xsd_contents = urllib2.urlopen(xsd_url).read()
>>> xmlschema_doc = etree.fromstring(xsd_contents)
>>> xmlschema=etree.XMLSchema(xmlschema_doc)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "xmlschema.pxi", line 102, in lxml.etree.XMLSchema.__init__ (src/lxml/lxml.etree.c:168126)
lxml.etree.XMLSchemaParseError: Element '{http://www.w3.org/2001/XMLSchema}pattern': 
The value '\w{2,3}|' of the facet 'pattern' is not a valid regular expression., line 58

对于这个更好的正则表达式模式是什么? (\w{2,3})?也因xsd失败,所以它需要是别的。

0 个答案:

没有答案