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 to share