regex - Java Reg accepts * which is not in [0-9]*[ -/]{0,1}[0-9]* - is it a bug? -


this question has answer here:

the following regex [0-9]*[ -/]{0,1}[0-9]* matches e.g. 1*2.

the * not defined in regex , not intended; space before - needs not escaped (as far found out)

if use 2 character of [ -/], 1*2 not match.

when change order e.g. [0-9]*[-/ ]{0,1}[0-9]*, 1*2 not matching (like expected).

do miss or bug?

i have behaviour java 7 , on http://www.regexplanet.com/advanced/java/index.html

update regex used in bean validation @pattern(regexp = "[0-9][ -/]{0,1}[0-9]").

[ -/] character class, , in character class, - range operator. "any character in range of characters 'space' 'slash', inclusive".

that means uses ascii table (basically) match characters [space], !, ", #, $ etc... /.

however, ranges work in postive direction: low ascii code high ascii code. when go high->low, range doesn't apply, , it's looking 3 characters: [space], dash , slash.

e.g. in easier read example:

ascending:    [b-g] -> matches 'b', 'c, 'd', 'e', 'f', or 'g' descending:   [g-b] -> matches 'g', '-', or 'b' 

Comments

Popular posts from this blog

html - Firefox flex bug applied to buttons? -

html - Missing border-right in select on Firefox -

c# - two queries in same method -