Consider the following tweets:
RT @username This is my tweet
Check this! RT @username This is my tweet
I have PART 2 downloaded
In a preg_replace() call, I am using regex to replace the RT (common retweet syntax) with {RT}. It almost works, however, it also matches RT in PART in the last tweet:
I have PART 2 downloaded becomes I have PA{RT} 2 downloaded
I want the regex to only allow nothing (beginning of string) or a space (U+0020) in front of RT.
The current preg_replace() call:
echo preg_replace("(\RT(?=\s)/", '{RT}', $tweet);
Use \b for word boundary matching. \bRT\b
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With