Menu

#317 XML Tools plug-in rejects valid RegEx

Not relevant
open
nobody
None
5
2018-01-22
2016-09-20
James Clark
No

We have an XML schema that includes a RegEx to validate valid decimal / hex numeric input. This works with other RegEx enabled tools. It is designed to pass valid decimal numbers (e.g. 1234) and valid hex numbers with 0x prefix (e.g. 0x12AB):

<xs:simpletype name="hexdec">
<xs:restriction base="xs:string">
<xs:pattern value="\b(0x&lt;span&gt;[0-9a-zA-Z]&lt;/span&gt;+|&lt;span&gt;[0-9]&lt;/span&gt;+)\b">
</xs:pattern></xs:restriction>
</xs:simpletype>

When this schema is loaded into the XML Tools plug-in it reports that the RegEx is "not a valid regular expression).

Discussion

  • Vyacheslav Nikolaev

    XML Tools version: 2.4.9.2. Unicode
    libXML 2.9.3
    libXSTL 1.1.28

    Same problem. Have in xsd:

    <xs:simpletype name="ttime">
    <xs:restriction base="xs:string">
    <xs:pattern value="^(?:(?:(&lt;span&gt;[01]&lt;/span&gt;?\d|2&lt;span&gt;[0-3]&lt;/span&gt;):)?(&lt;span&gt;[0-5]&lt;/span&gt;?\d):)?(&lt;span&gt;[0-5]&lt;/span&gt;?\d)$">
    </xs:pattern></xs:restriction>
    </xs:simpletype>

    When validate XML:


    XML Tools plugin

    Unable to parse schema file.

    Parsing error at line 6634:

    Element '{http://www.w3.org/2001/XMLSchema}pattern': The value '^(?:(?:([01]?\d|2[0-3]):)?([0-5]?\d):)?([0-5]?\d)$' of the facet 'pattern' is not a valid regular expression.

     
  • Nicolas Crittin

    Nicolas Crittin - 2016-12-02

    Are you sure you reged is valid ? The regex of your first post looks quite strange... it contains <span> strings which has nothing to do with decimal parsing. Same with the regex of your second post. I guess it was transformed when posting.

    Now if I focus on the regex ^(?:(?:([01]?\d|2[0-3]):)?([0-5]?\d):)?([0-5]?\d)$ which is given in xmltools validation error: this regex is already wrong. I've tried to use it in a xsd file and even XMLSpy indicates it's wrong:

    File U:\Documents\Progs\Visual C++\XMLToolsPlugin 64bit\tests\hexdec.xsd is not valid.
        Value '^(?:(?:([01]?\d|2[0-3]):)?([0-5]?\d):)?([0-5]?\d)$' is not a valid XML regular expression.
            Error location: xs:schema / xs:simpleType / xs:restriction / xs:pattern / @value
            Details
                Value '^(?:(?:([01]?\d|2[0-3]):)?([0-5]?\d):)?([0-5]?\d)$' is not a valid XML regular expression.
    
     
  • Vyacheslav Nikolaev

    Regexp valid, see examlpe:
    http://regexr.com/3eq39
    We use this regexp more 3 years

    i thing intenal editor add 'span' in my exmaple.
    normal code:

      <xs:simpleType name="ttime">
        <xs:restriction base="xs:string">
          <xs:pattern value="^(?:(?:([01]?\d|2[0-3]):)?([0-5]?\d):)?([0-5]?\d)$" />
        </xs:restriction>
    
     
  • Nicolas Crittin

    Nicolas Crittin - 2016-12-03

    The "?:" pattern is a noncapturing group (http://speakingjs.com/es5/ch19.html). I don't think it exists in XSD (you only define pattern to match an expression, not to replace elements). "^" and "$" are not useful too.
    Therefore, following pattern should do the same and should work:

    <xs:pattern value="((([01]?\d|2[0-3]):)?([0-5]?\d):)?([0-5]?\d)"/>
    
     
  • Vyacheslav Nikolaev

    yes, apply simple regex and error gone.
    but, we need ?: to greate capture-group.
    New regexp create 5 group, we need only 3.
    I think the validator does not produce an error.

     
  • greensweater

    greensweater - 2018-01-19

    Same issue, following valid regex fails:

    (?![cC][rR][mM]_)([A-Za-z0-9])+([_])+([A-Za-z0-9_])*

     
  • greensweater

    greensweater - 2018-01-19

    another: (\$webresource:|/)(.)+

     
  • Tomas Lionikas

    Tomas Lionikas - 2018-01-22

    I have also come across the same with:

    <xsd:simpleType name="groupPathType">
        <xsd:restriction base="xsd:string">
          <xsd:pattern value="((\s\/\s)([\w\s-_])+(\w))+"/>
        </xsd:restriction>
      </xsd:simpleType>
    
     

Log in to post a comment.

MongoDB Logo MongoDB