How to match hyphens with Regular Expression?

后端 未结 6 1135
[愿得一人]
[愿得一人] 2020-11-21 23:36

How to rewrite the [a-zA-Z0-9!$* \\t\\r\\n] pattern to match hyphen along with the existing characters ?

6条回答
  •  后悔当初
    2020-11-21 23:56

    Escape the hyphen.

    [a-zA-Z0-9!$* \t\r\n\-]
    

    UPDATE:
    Never mind this answer - you can add the hyphen to the group but you don't have to escape it. See Konrad Rudolph's answer instead which does a much better job of answering and explains why.

提交回复
热议问题