If I have a string like "11E12C108N" which is a concatenation of letter groups and digit groups, how do I split them without a delimiter space character inbetween?
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 this 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());
}
}
Which gives me:
11E
12C
108N
Can I make the original regex do a complete split in one go? Instead of having to run the regex again on the intermediate tokens?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…