I’m parsing a tweet as a quick way of adding reminders to a database. The tweet would look something like this:
$tweet = '#notes @username !high_priority [Project Name] Tweet content';
I’m using the following regex to get the #, @, ! and [Project]
$match = preg_match_all('/(#\\w*[a-zA-Z_]+\\w*)|(!\\w*[a-zA-Z_]+\\w*)|(@\\w*[a-zA-Z_]+\\w*)|(\\[[^\\]]*\\])/i',
$tweet,
$matches);
I want to know how to also get the remaining “Tweet content”, so everything that does’t match the regex should be saved into a variable.
Also, will the match order matter if the tweet is something more like:
$tweet = '@username Tweet content [Project Name] #notes !high_priority';
Does anyone know how to do that?
Replace the text your regular expression matches with an empty string. What’s left is what wasn’t matched by the regex.