So "XXXXX**".matches("[X{9,11}\*{2,3}]")
returns false
as expected...
But, "XXXXX**".matches("[X{9,11}\*{2,3}]+")
returns true
. Am I using the +
quantifier correctly? (I want the second one to also return false
)
So "XXXXX**".matches("[X{9,11}\*{2,3}]")
returns false
as expected...
But, "XXXXX**".matches("[X{9,11}\*{2,3}]+")
returns true
. Am I using the +
quantifier correctly? (I want the second one to also return false
)
[...]
matches any character defined in the character class, so
[X{9,11}\*{2,3}]
actually means, a single character which is: X, or open brace, or 9, or comma, or 1, or 1 (yes you have it duplicated), or backslash, or asterisk....
So as your string have more than character in your string to-be-matched, such pattern will not match.
When you add a +
, it means matching a string with 1 or more [ X or asterisk or....], so it match
I believe what you really want to do is using a group.
So the regex looks like (X{9,11}*{2,3}])+