How to rewrite the [a-zA-Z0-9!$* \\t\\r\\n]
pattern to match hyphen along with the existing characters ?
The hyphen is usually a normal character in regular expressions. Only if it’s in a character class and between two other characters does it take a special meaning.
Thus:
[-]
matches a hyphen.[abc-]
matches a
, b
, c
or a hyphen.[-abc]
matches a
, b
, c
or a hyphen.[ab-d]
matches a
, b
, c
or d
(only here the hyphen denotes a character range).