I have the current regular expression:
/(?<=[\s>]|^)#(\w*[A-Za-z_]+\w*)/g
Which I'm testing against the string:
Here's a #hashtag and here is #not_a_tag; which should be different. Also testing: Mid#hash. #123 #!@£ and <p>#hash</p>
For my purposes there should only be two hashtags detected in this string. I'm wondering how to alter the expression such that it doesn't match hashtags that end with a ;
in my example this is #not_a_tag;
Cheers.
How about the following:
\B(\#[a-zA-Z]+\b)(?!;)
Regex Demo
This is the best practice.
(#+[a-zA-Z0-9(_)]{1,})
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With