I’m trying to extract from a string like this:
$message = #porrabarça per avui @RTorq el @FCBar guanyarà per 3-1 al AC Milan
The ‘3-1’. As Number – Number
I’ve tried
$message = preg_replace('/[0-9]\s*-\s[0-9]/i', '', $message);
But it isnt working. It’s output is the same as the input.
Can you help me out?
The problem is
\shere.You need
\s*there. Usepreg_matchto extract anything.preg_matchmatches and optionally set the match to a variable. From there you can extract the matches.preg_replacereplaces the matched content.http://ideone.com/BWKZQV
To replace use this pattern and empty string as replace string in
preg_replace.A better pattern would using POSIX character classes. it’ll match any type digit characters of any other locale.