[Solved] Break a string (having alphabetic and alphanumeric values) in 2 parts


You’re on the right track with what you have.

You are currently only trying to get the numeric characters, which is why that’s all you are getting. Also, after some testing with different strings, it turned out that your particular regex seems to only works when all the numbers are next to each other. I figured out a way to do this with preg_replace instead of preg_match.

Try this:

$string2 = '4s5ee9f8fg';
$result1 = preg_replace("/[A-z]+/", "", trim($string2));
$result2 = preg_replace("/[0-9]+/", "", trim($string2));
$finalResult = $result1." ".$result2;
echo $finalResult."\n";

solved Break a string (having alphabetic and alphanumeric values) in 2 parts