Thomas Anderson Thomas Anderson - 1 month ago 12
C# Question

How to match hyphens with Regular Expression?

How to rewrite the

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

Answer

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.