If I have say "ic182nob2"
I would like to split that into an array list string of
["i","c", "182", "n", "o", "b", "2"]
I tried the split string with regex, but i ended up getting "ic", "182", "nob", "2" which is not what i want
>Solution :
We can try splitting on the regex alternation (?<=\\D)|(?=\\D):
String input = "ic182nob2";
String[] parts = input.split("(?<=\\D)|(?=\\D)");
System.out.println(Arrays.toString(parts)); // [i, c, 182, n, o, b, 2]
The above logic makes a split when either the preceding or following character is not a digit:
(?<=\\D) what precedes is not a digit
| OR
(?=\\D) what follows is not a digit