If I have a string like "11E12C108N", which is a concatenation of letter groups and number groups, how can I separate them without a space character between them?
For example, I want the resulting split to be:
tokens[0] = "11" tokens[1] = "E" tokens[2] = "12" tokens[3] = "C" tokens[4] = "108" tokens[5] = "N"
I have it right now.
public static void main(String[] args) { String stringToSplit = "11E12C108N"; Pattern pattern = Pattern.compile("\\d+\\D+"); Matcher matcher = pattern.matcher(stringToSplit); while (matcher.find()) { System.out.println(matcher.group()); } }
What gives me:
11E 12C 108N
Can I make the original regex to completely split at a time? Instead of running regex on intermediate tokens again?
source share