Getting illegal character range in regex :java

前端 未结 1 1044
情话喂你
情话喂你 2021-01-24 06:00

I have a simple regex pattern that verifies names. But When I run it I get illegal character range error. I thought by escaping \"\\s\" it will allow a space but the compiler is

相关标签:
1条回答
  • 2021-01-24 06:04

    You can't have a range "from , to whitespace". Perhaps you meant to escape -?

    \s is not a space, it's [ \t\r\n\v\f] (space, tab, carriage return, newline, vertical tab or a form feed).

    Things that will work:

    "[ ',-]"
    
    "[',\\- ]"
    
    0 讨论(0)
提交回复
热议问题