Suppose you have the following JavaScript code snippet:
var string = "A111B222C333D444E555";
var arr = string .match(/.{1,4}/g);
This piece of code splits the string into an array every 4 characters and formats it correctly as:
0 => A111
1 => B222
3 => C333
4 => D444
5 => D555
The issue arises when the letter-number combination does not consistently contain 4 characters. For instance, with the string A11B22C33D44E555
, the result would be:
0 => A11B
1 => 22C3
3 => 3D44
4 => E555
However, we desire the output format to be:
0 => A11
1 => B22
3 => C33
4 => D44
5 => E55
Is there a way to split the string before each new letter without being concerned about the number of digits after each letter?