I\'ve been looking through pages and pages of Google results but haven\'t come across anything that could help me.
What I\'m trying to do is split a string like
Try this
String s = "Bananas22Apples496Pears3";
String[] res = s.replaceAll("(?<=\\p{L})(?=\\d)", ":").split("(?<=\\d)(?=\\p{L})");
for (String t : res) {
System.out.println(t);
}
The first step would be to replace the empty string with a ":", when on the left is a letter with the lookbehind assertion (?<=\\p{L})
and on the right is a digit, with the lookahead assertion (?=\\d)
.
Then split the result, when on the left is a digit and on the right is a letter.
\\p{L}
is a Unicode property that matches every letter in every language.