RE: Patterns and Decimal

On Thu, 2003-02-27 at 15:42, Anli Shundi wrote:
> I think the regular expressions should be rewritten
> to escape the dot, i.e.
> 
>   <xsd:pattern value = "[0-9][\.][0-9]*"/> 
>   <xsd:pattern value = "[1-9][0-9]*[\.][0-9]*"/>
>   <xsd:pattern value = "[1-9][0-9]*"/>
> 
> If the dot is unescaped it matches any character,
> thus "[0-9][.][0-9]*" matches 0123.

No.  "[.]" is a perfectly valid way to match a literal ".".  See:

http://www.w3.org/TR/2001/REC-xmlschema-2-20010502/#nt-charRange

It is equivalent to "[\.]" and to "\.".

Personally, I'd write it as (0\.[0-9]*|[1-9][0-9]*(\.[0-9]*)?)

but in fact, I'd probably want: (0(\.[0-9]+)?|[1-9][0-9]*(\.[0-9]+)?)

as this allows "0", but forbids "0." and "123." etc.

Paul

Received on Thursday, 27 February 2003 11:11:34 UTC