get word before a :- sign in a string with regex
I need to get the amount before a :- sign. So the string开发者_Go百科 would be: bla bla 120:-
And then store only 120 in a variable
preg_match_all('!(\d+):-!', $string, $matches);
print_r($matches);
This should do it. It captures anything up to a whitespace before ":-"
The regex
/(-?\d+):-/
will capture any digits (and a negative sign, if it's there) before a ":-" in the string.
You can than parse that into a number and store it.
精彩评论