regex - How to split number and character of string using php?


Keywords:php 


Question: 

This question already has an answer here:


1 Answer: 

Use regex in preg_match_all() function to select target parts of string.

$str = "B234CR45SV42";
preg_match_all("/[A-Z]+|\d+/", $str, $matches);
print_r($matches[0]);

See result in demo