Reputation: 5960
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.
Upvotes: 5
Views: 4837
Reputation: 31035
You don't need a regex look around, you can use a simple regex like this:
\B@\w+
Upvotes: 5