Reputation: 401
Pretty basic, how can I take [a-zA-Z0-9_-]
and include #
.
Upvotes: 0
Views: 42
Reputation: 1527
You can do it like this too
[\w-#]
\w
match any word character [a-zA-Z0-9_]
-
matches the character -
literally
#
matches the character #
literally
Upvotes: 1
Reputation: 70732
Simply add any extra characters you want to allow to the character class.
[a-zA-Z0-9_#-]
↑
Additional note: (in case you're getting an invalid range error)
Inside of a character class the hyphen has special meaning. You can place it as the first or last character of the class. In some regex implementations, you can also place directly after a range. If you place the hyphen anywhere else you need to precede it with a backslash in order to add it to your character class.
Upvotes: 4