Sean McVeigh
Sean McVeigh

Reputation: 599

Substitue non-capturing groups for regex in XML Schema?

I'm linting my first custom XML Schema and lxml gets caught on the expression representing a tuple such as "10.1,-900":

<xs:simpleType name="pair_dec">
    <xs:restriction base="xs:string">
        <xs:pattern value="-?\d+(?:.\d+),-?\d+(?:.\d+)"/>
    </xs:restriction>
</xs:simpleType>

I've read that this is because there is no support for non-capturing groups. Is this right and is there a work around?

Upvotes: 0

Views: 503

Answers (1)

Wiktor Stribiżew
Wiktor Stribiżew

Reputation: 626926

Mind that in XSD regex flavor:

  • Non-capturing groups are not supported, but can be replaced with capturing ones
  • \d and all other shorthand character classes are Unicode aware, so it is safer to use [0-9] instead of \d
  • A dot must be escaped to match a literal dot

Use

<xs:pattern value="-?[0-9]+(\.[0-9]+)?,-?[0-9]+(\.[0-9]+)?"/>

Upvotes: 1

Related Questions