Home>Knowledge Base>Root>Liquid XML Data Binding>Issues with complex regular expressions
Information
Article ID40
Created On3/20/2009
Modified1/19/2010
Share With Others

Issues with complex regular expressions

In xsd the whole pattern must match for it to be valid, but with many regex patterns, the pattern only matches part which then returns false.

E.g. With the patern:
         <xs:pattern value="[0-9]{1,8}|([0-9]{9,14}|[0-9]{14,14}\.[0-9]+)([+\-][0-9]{1,4})?"/>

When the value is read from the xml document: "20071029130945-0400"

It matches the first part of the regex, i.e. the first 8 chars "20071029" match against [0-9]{1,8}. But in xsd this is invalid as the length of the match is not the same as the length of the whole string.

As a work around, to resolve this you can simply swap the regex around, the the largest match part comes first:
         <xs:pattern value="([0-9]{9,14}|[0-9]{14,14}\.[0-9]+)([+\-][0-9]{1,4})|[0-9]{1,8}?"/>

Now the whole string matches.