I have a string that contains either an alphabet or a number.
AB1D21E48EFGHI1K
I am trying to break that string into array as follows.
[0] => A
[1] => B
[2] => 1
[3] => D
[4] => 21
[5] => E
[6] => 48
[7] => E
[8] => F
[9] => G
[10] => H
[11] => I
[12] => 1
[13] => K
But, I am getting array as follow:
[0] => Array (
[0] => AB
[1] => 1
[2] => D
[3] => 21
[4] => E
[5] => 48
[6] => EFGHI
[7] => 1
[8] => K
)
I have tried the following code so far.
$string = 'AB1D21E48EFGHI1K';
preg_match_all('/([0-9]+|[a-zA-Z]+)/', $string, $matches);
print_r($matches);
([0-9]+|[a-zA-Z]{1})or simpler(\d+|\w{1})