What is the difference between the two regex pattern

前端 未结 2 2017
深忆病人
深忆病人 2021-01-20 20:11

I was trying to validate a company name in a web application and had this regex pattern

^[a-zA-Z_\'\\\\s,;.-0-9]{1,100}$

The above pattern

2条回答
  •  耶瑟儿~
    2021-01-20 20:50

    It's probably because of the "-" inside the character group in the first one

    ^[a-zA-Z_'\s,;.\-0-9]{1,100}$
    

    Escaspe it and it should be fine.

    Remember, when inside the character group the chars you have to escape become

    backslash \
    caret ^
    hyphen -
    

提交回复
热议问题