I am having a hard time figuring out this XSD Regex match. Here is the simpleType defininition:
<xs:simpleType name="data-fuelcorrfact">
<xs:restriction base="xs:float">
<xs:pattern value="\-?[1-9]\.[0-9]{4}"/>
</xs:restriction>
</xs:simpleType>
I can guess that it needs a number between 1 and 9, a period, and another number betwen 0 and 9. I don’t understand what the \-? is and putting a value of 1.0 for example fails validation.
Can someone please help me decipher this regular expresion? Also, does anyone have any references for programs or websites that can explain a given XSD regex value should consist of? Thanks!
I’m not familiar with XSD, but assuming that is uses the usual RegEx rules, here’s the breakdown:
First,
\-?. That matches one or zero dashes, i.e. negative or not. The\is just an escape character, i.e. treat the-as an actual-character and not a special RegEx character. Outside of square brackets, though, it doesn’t usually have any special meaning. Might be an XSD thing.Next,
[1-9]matches any non-zero numeral character (i.e. 1, 2, 3, 4, 5, 6, 7, 8, or 9). So a single-digit number.The
\.does, in fact, match a period.Then we have
[0-9]{4}which matches exactly 4 numeral characters (including zero now).So it’s looking for any number in (-10, 10) but not in (-1, 1) with exactly four decimal places. Strange behavior; I suspect the
[1-9]should be[01-9]because it’s very weird to omit the values around 0 like that.