iss42
iss42

Reputation: 2816

Regular expression to exclude specific bit

So far I have this:

@(\w+)(?=\s|[.,?!:;-]|$)

Which works well for my purpose, except that it includes things like @@jhgdsj which I want to exclude. How would I exclude anything for more than one @ at the start of any "word"?

[Edit] Example here: example

Matches desired for bolded words (aaa, ddd, fff): @aaa then @@bbb also ccc@ccc and @ddd @fff not @@@ggg

Upvotes: 0

Views: 97

Answers (1)

Avinash Raj
Avinash Raj

Reputation: 174706

Just add the start pattern to allow only one @ at the start,

^@(\w+)(?=\s|[.,?!:;-]|$)

DEMO

OR

(?:^| )@(\w+)(?=\s|[.,?!:;-]|$)

DEMO

Upvotes: 3

Related Questions