I have a string that looks like abc,5,7
from which I want to get the numbers.
I've come up with this:
^(?<prefix>[a-z]+)(,(?<num1>\d+?))?(,(?<num2>\d+?))?$#i
but it will only work with 2 numbers, and my string has a variable number of numbers. I don't know how to change the regex to account for that. Help please
You can try this
<?php
$string = "abc,5,7";
$int = intval(preg_replace('/[^0-9]+/', '', $string), 10);
echo $int;
?>
Also you can Use this regular expression !\d!
<?php
$string = "abc,5,7";
preg_match_all('!\d!', $string, $matches);
echo (int)implode('',$matches[0]);
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments