php get the number from a string

php, preg-match, preg-match-all, regex

Solution

Don't forget the lookahead so you don't match `095032`:

$foo = '@[123:peterwateber] hello there 095032sdfsdf! @[589:zzzz]';
preg_match_all("/[0-9]+(?=:)/", $foo, $matches);
var_dump($matches[0]); // array(2) { [0]=> string(3) "123" [1]=> string(3) "589" }

Problem

I have this string @[123:peterwateber] hello there 095032sdfsdf! @[589:zzzz] I want to get 123 and 589 how do you that using regular expression or something in PHP? Note: peterwateber and zzzz are just examples. any random string should be considered

Original source