I’m trying to find all the hash tags in a string. The hashtags are from a stream like twitter, they could be anywhere in the text like:
this is a #awesome event, lets use the
tag #fun
I’m using the .NET framework (c#), I was thinking this would be a suitable regex pattern to use:
#\w+
Is this the best regex for this purpose?
It depends on whether you want to match hashtags inside other strings (“Some#Word”) or things that probably aren’t hashtags (“We’re #1”). The regex you gave
#\w+will match in both these cases. If you slightly modify your regex to\B#\w\w+, you can eliminate these cases and only match hashtags of length greater than 1 on word boundaries.