I want to match all strings that start with an @ unless they have other characters in front of the @ as well. Simple example: in @one @two and bla@three
I want to match @one
and @two
but not @three
. It's for highlighting usernames in a chatroom.
These strings can be anywhere in a sentence (right at the start or in the middle).
I actually thought that (?![a-zA-Z])@[a-zA-Z]+
should work but it still matches @three
too.
You don't need a regex look around, you can use a simple regex like this:
\B@\w+
Working demo
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