Frooplet
Frooplet

Reputation: 208

Javascript: hashtag regex not working

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

Answers (1)

Hodrobond
Hodrobond

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

Related Questions