Why does Pattern/Matcher work with (\\d+)([a-zA-Z]+) but String.split() doesn't ?
For example:
String line = "1A2B"; Pattern p = Pattern.compile("(\\d+)([a-zA-Z]+)"); Matcher m = p.matcher(line); System.out.println(m.groupCount()); while(m.find()) { System.out.println(m.group()); } Prints :
2 1A 2B But :
String line = "1A2B"; String [] arrayOfStrings = line.split("(\\d+)([a-zA-Z]+)"); System.out.println(arrayOfStrings.length); for(String elem: arrayOfStrings){ System.out.println(elem); } Prints only:
0
splitis a delimiter whereas in the case of matcher it's a "pattern" used to match your expression of choice...