is possible perform these two function converting in a regular expression?
// Get all alpha-substring to left and before of any digits
// otherwise return empty string.
function ex1($source) {
$string_alpha = "";
$tmp = substr($source, 0, strcspn($source, '0123456789'));
if (ctype_alpha($tmp)) {
$string_alpha = $tmp;
}
return $string_alpha;
}
// Get all numeric-substring to right and after last letter
// otherwise return empty string.
function ex2($source) {
$string_numeric = "";
$tmp = substr($source, strcspn($source, '0123456789'));
if (ctype_digit($tmp)) {
$string_numeric = $tmp;
}
return $string_numeric;
}
$source = "butterfly12";
echo "ex1 function => " . ex1($source) . "<br>";
echo "ex2 function => " . ex2($source) . "<br>";
// Output:
// ex1 function => butterfly
// ex2 function => 12
I have tried to code about i need to do with these two example. Thanks very much.