I have encountered this pattern
(\w+)
and from http://gskinner.com/RegExr/ site I understand that \w = match alpha-numeric characters and underscores, and + = match previous token 1 or more times (not exactly sure what that means).
How can I add the hyphen character to the list?
I tried (\w\-+) but it doesn’t work, I don’t get any match …
You need a character class, denoted by
[...].\wcan then be used in the character class and more characters can be added:Careful though, if you add more characters to match. The hyphen-minus needs to be first or last in a class to avoid interpreting it as a range (or escape it accordingly).
The
+is a quantifier, so it goes after a token (where the whole character class is a single token [as is\w]):