views:

55

answers:

1

I need to extract the digits from the following string using regular expression:

pc 32444 xbox 43567

so my array will be

array ([0] => 32444 [1] => 43567)

Can someone help construct a preg_match for me?

Thanks!

+2  A: 

Try this regular expression:

/\d+/

But you would need to use preg_match_all to get all matches:

preg_match_all('/\\d+/', $str, $matches)

$matches[0] will then contain the array you’re looking for.

Gumbo