Get 12 digits out of a string with regex

if I have this string:
$string = ‘Product: 485923039484 item name here’;

it is possible to extract those 12 numbers and/or get rid of everything else with a regex?

so i want $string to equal ‘485923039484’;

thanks

Perfect, thanks!

Sorry, $string looks like the below, so i can’t just delete everything that is not a number:

$string = ‘Product: 485923039484 item name 351 here’;

i just need the set of 12 numbers


$string = 'Product: 485923039484 item name 351 here';
preg_match('~\\d{12}~', $string, $pres);
$string = $pres[0];
echo $string; // echoes 485923039484

:slight_smile: