Reputation: 535
That is to say, alice should be matched, but bob shouldn't in the following
Hello @alice and [@bob](...)
I can match the names themselves with the following simple regex: /\@([\w]+)/
.
Does anyone know how to make the regex not match bob?
Upvotes: 0
Views: 94
Reputation: 174706
Group index 1 contains the characters you want.
Use a negative looahead.
@(?![^\[\]]*])(\w+)
OR
Through alteration,
\[.*?\]|@(\w+)
OR
Through PCRE verb (*SKIP)(*F)
\[.*?\](*SKIP)(*F)|@(\w+)
Upvotes: 2