The patterns are,
1. <xsd:pattern value = "[0-9][0-9]*"/>
and
2. <xsd:pattern value = "[0-9]*"/>
it produce the same result. So what is the difference be开发者_StackOverflowtween them? Thanks in advance.
The first one will match 1 or more digits. The second one will match 0 or more digits.
The *
character means that the previous thing can be repeated 0 or more times for the pattern to be matched.
So, [0-9][0-9]*
means "match 1 digit, followed by 0 or more digits", whereas [0-9]*
means "match 0 or more digits (which means that the empty string will be matched as well)".
The first pattern says, the first two characters have to be one of 0 to 9 and the rest anything, but the second pattern says the first character has to be 0 to 9 and the rest can be anything.
They don't mean the same thing at all, but they both would pass where there are digits in the string.
[0-9]* will match strings without any digits at all, even empty strings, while [0-9][0-9]* requires at least one digit.
精彩评论