Whenever a Tweet is retweeted, the retweeting tweet usually has the same format:
RT @UserName: Original Tweet, sometimes with alterations
I’m looking for a way to split off the “RT @UserName:”, so that only the original tweet remains. I think a regex checking the beginning of the tweet for “RT”, and then check until the first space after @UserName should do the trick. I now have
preg_replace("/^RT/ui", "", $tweet);
but this only removes the RT. How can I expand this regex?
Second question: alternatively, it would probably also be possible to check for “RT” at the beginning of the tweet, and then only save the part of the string after the second space (first one is between RT and @UserName, so the first one after @UserName indicates the cut-off point), but then I would have a problem if for some reason there would be two spaces between RT and @UserName, for instance.
This will remove everything until the colon.
EDIT:
Apparently some retweets don’t have a colon:
This will remove “RT”, the username, an optional colon and also the spaces before the message.