Getting illegal character range in regex :java -
i have simple regex pattern verifies names. when run illegal character range error. thought escaping "\s" allow space compiler still complaining.
public boolean verifyname(string name) { string namepattern = "^[\\p{l}]++(?:[',-\\s][\\p{l}]++)*+\\.?$"; return name.matches(namepattern); }
and error think shouldn't occurring since name might contain anny of these [',-\\s]
so not understanding?
you can't have range "from ,
whitespace". perhaps meant escape -
?
\s
not space, it's [ \t\r\n\v\f]
(space, tab, carriage return, newline, vertical tab or form feed).
things work:
"[ ',-]" "[',\\- ]"
Comments
Post a Comment