Search code examples
regexmatchtweets

Regex in a Tweet: match @reply WITHOUT matching @mention


I am working with Tweets.

I am looking for a regular expression that matches all the replies @reply that are present in the beginning of a Tweet WITHOUT matching the mentions @mention.

For example I have this Tweeet:

@AlexWassabi @laurDIY now i type my text and i mention @mention

I would like to match @AlexWassabi and @laurDIY WITHOUT matching @mention.

Please note that in this example there are 2 replies (e.g @AlexWassabi and @laurDIY) but in reality we can have more @replies that are followed by each other, then we have text and then we have a mention.

Could please suggest a regular expression that does this job?

Thank you.


Solution

  • ^(@\w+\s)+ will match all the prefixed "@reply"(s) at beginning of string only. regex101.com demo