php - Match only the first set of numbers in a string -


i need retrieve first set of numbers string, i'm not sure how.

i have following, expecting pick each set of numbers pick first key $matches array, literally matches first number.

in example i'd looking '123'. can please let me know how regex (or better way if regex not best job). thanks.

$e = 'abc 123,456,def, 789-ab-552'; // random example $pattern = "/[0-9]/"; preg_match($pattern, $e, $matches); 

you must add quantifier:

$pattern = "/[0-9]+/"; 

+ means one or more

you can find ajax regex tester php here , more informations regular expressions here.


Comments