Reputation: 208
I have the following Regex in javascript to find all hashtags in a string:
string.match(/#([^\s]+)/g);
This works fine as long as the hashtag is not followed by an HTML tag.
https://regex101.com/r/pJ4wC5/139
Can anybody help? Thanks in advance!
Upvotes: 0
Views: 74
Reputation: 1695
Try #([^\s<]+)
.
The ^\s...
is whatever you don't want matched. Right now it looks to just be whitespace. Adding <
additionally says "don't match <
"
Upvotes: 1