I've been trying to dry up the following regexp that matches hashtags in a string with no success:
/^#(\w+)|\s#(\w+)/i
This won't work:
/^|\s#(\w+)/i
And no, I don't want to comma the alternation at the beginning:
/(^|\s)#(\w+)/i
I'm doing this in Ruby - though that should not be relevant I suppose.
To give some examples of matching and non-matching strings:
'#hashtag it is' # should match => [["hashtag"]]
'this is a #hashtag' # should match => [["hashtag"]]
'this is not a#hashtag' # should not match => []
Any suggestions? Am I nitpicking?