Regex pattern including all special characters

后端 未结 18 1553
爱一瞬间的悲伤
爱一瞬间的悲伤 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:45

    For people (like me) looking for an answer for special characters like Ä etc. just use this pattern:

    • Only text (or a space): "[A-Za-zÀ-ȕ ]"

    • Text and numbers: "[A-Za-zÀ-ȕ0-9 ]"

    • Text, numbers and some special chars: "[A-Za-zÀ-ȕ0-9(),-_., ]"

    Regex just starts at the ascii index and checks if a character of the string is in within both indexes [startindex-endindex].

    So you can add any range.

    Eventually you can play around with a handy tool: https://regexr.com/

    Good luck;)

提交回复
热议问题