Regex find all words starting with @ but ignore email addresses

I created this regex to match all words starting with "@" in my string, maybe something else before @ tokens. it works well, but it catches email addresses too and I would like to fix that.

(?<=@)\w+\b

      

Example line:

hello @bob, how are you? @mark, @emma and @chief with me. Email me at test@email.com !

You can help?

+3


source to share


3 answers


You can use the following expression:

\B@\w+

      



which starts with a no-word boundary ( \B

). You can also rewrite it using negative lookahead like this:

(?!\b)@\w+

      

+3


source


Test the space before @



0


source


My suggestion is this.

[\s]?\B@\w+

I tested it in Regex Designer from RAD Software and it matches every word starting with @. With or without space in front of it.

Hope it helped;)

0


source







All Articles