Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Negative lookbehind regex in Javascript

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.

like image 259
Kevin Renskers Avatar asked Apr 10 '14 22:04

Kevin Renskers


Video Answer


1 Answers

You don't need a regex look around, you can use a simple regex like this:

\B@\w+

Working demo

enter image description here

like image 102
Federico Piazza Avatar answered Oct 13 '22 03:10

Federico Piazza