Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy am I getting different validation between an XSD regex with Nokogiri and normal Ruby regular expressions?
    primarykey
    data
    text
    <p>I have an XSD schema that includes a rule for a specific field to match the following regex:</p> <pre><code>\d{8}[\-]?[A-Za-z]{0,3} </code></pre> <p>Using irb, I can test with this regex and the following strings all match, which is correct:</p> <pre><code>12345678 12345678- 12345678-abc 12345678abc </code></pre> <p>When I attempt to validate some XML against this XSD, I get slightly different behaviour:</p> <pre><code>Passes: 12345678- 12345678-abc 12345678abc Fails: 12345678 </code></pre> <p>And here is a mimimal XSD/XML files that reproduces this:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema"&gt; &lt;xs:simpleType name="codeType"&gt; &lt;xs:restriction base="xs:token"&gt; &lt;xs:pattern value="\d{8}[\-]?[A-Za-z]{0,3}"/&gt; &lt;/xs:restriction&gt; &lt;/xs:simpleType&gt; &lt;xs:element name="test"&gt; &lt;xs:complexType&gt; &lt;xs:sequence&gt; &lt;xs:element type="codeType" name="code"/&gt; &lt;/xs:sequence&gt; &lt;/xs:complexType&gt; &lt;/xs:element&gt; &lt;/xs:schema&gt; </code></pre> <p>And XML:</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;test&gt; &lt;code&gt;11034755&lt;/code&gt; &lt;/test&gt; </code></pre> <p>And running this with</p> <pre><code>xmllint --schema test.xsd test.xml </code></pre> <p>Gives </p> <pre><code>Element 'code': [facet 'pattern'] The value '11034755' is not accepted by the pattern '\d{8}[\-]?[A-Za-z]{0,3}' </code></pre> <p>While XML schema does not have full regular expressions, this should be valid I think. What am I not understanding when it comes to regular expressions in XSD files in this particular case with regards to '?' ?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload