Regex pattern including all special characters

后端 未结 18 1542
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-02 09:18

I want to write a simple regular expression to check if in given string exist any special character. My regex works but I don\'t know why it also includes all numbers, so wh

18条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-02 09:38

    That's because your pattern contains a .-^ which is all characters between and including . and ^, which included digits and several other characters as shown below:

    enter image description here

    If by special characters, you mean punctuation and symbols use:

    [\p{P}\p{S}]
    

    which contains all unicode punctuation and symbols.

提交回复
热议问题