tags:

views:

53

answers:

2

I need to get the amount before a :- sign. So the string would be: bla bla 120:-

And then store only 120 in a variable

+4  A: 
preg_match_all('!(\d+):-!', $string, $matches);
print_r($matches);

This should do it. It captures anything up to a whitespace before ":-"

bisko
or \d+ in place of \S+ if you only want to match numbers.
Grandpa
because he's asking for an "amount" and that would allow for anything (including non-numeric values) before the :-
theraccoonbear
Yes I saw it, but not before posting the answer. Corrected it ;) Sorry for the stupid mistake.
bisko
+1  A: 

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.

Anon.