I want to strip off the # from twitter hash-tags, so:
Input: I love #winter and #ice-skating
Output: I love winter and ice-skating
I thought th
1
in the replacement string with curly braces$tweet = preg_replace('/#([^\s]*)/', '$1', $tweet);
Faster solution:
$tweet = str_replace('#', '', $tweet)
No regex required
You need to surround the part you want to capture in parentheses:
$tweet = preg_replace('/#([\w-]+)/i', '$1', $tweet);
See it working online: ideone
I also changed the regular expression to be more specific, but for an even better regular expression I refer you to this question and its answers (for .NET but the idea is the same in PHP):