Reputation: 7941
/(?:\s|^)(?:#(?!(?:\d+|\w+?_|_\w+?)(?:\s|$)))(\w+)(?=\s|$)/i
This is the current expression i use. It works fine except the dash -
is not allowed. I need this: #what-ever
to be captured.
How can i add the dash
to this expression ?
Upvotes: 0
Views: 86
Reputation: 174874
Just add the pattern which was present inside the first capturing group that is \w
plus -
into a character class. So that it would capture a word character or a -
symbol. +
after the character class makes the previous token to repeat one or more times.
(?:\s|^)(?:#(?!(?:\d+|\w+?_|_\w+?)(?:\s|$)))([-\w]+)(?=\s|$)
|here|
Upvotes: 1