Jessica
Jessica

Reputation: 33

Regex for removing RT

I have the following input string:

 "i'm good RT @someone : how are you?"

I want to remove everything after i'm good for having a final string like below:

 "i'm good"

Here the regex I had so far:

/ RT\s*@[^:]*:\s*[A-Za-z ]/

However, only ' RT @someone :' is removed, the status is still on.

What am I missing?

Upvotes: 1

Views: 982

Answers (2)

Stephan
Stephan

Reputation: 43023

Try this regex:

\s*RT\s*@[^:]*:.*

Regular expression visualization

DEMO

Upvotes: 1

vks
vks

Reputation: 67968

RT\s*@[^:]*:\s*[A-Za-z ]+

You need to add a quantifier like * or + to remove status as well.

or

RT\s*@[^:]*:\s*.*

Upvotes: 0

Related Questions