Thomas Anderson Thomas Anderson - 5 months ago 31
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 ?


Escape the hyphen.

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

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.