String s = "A..?-B^&';(,,,)G56.6C,,,M4788C..,,A1''";
String[] result = s.split("(?=[ABC])");
System.out.println(Arrays.toString(result));
Output:
[A..?-, B^&';(,,,)G56.6, C,,,M4788, C..,,, A1'']
Please refer to the The split in the above case. I am trying to separate strings based on A, B orC. How can I get the the same split strings into an ArrayList using pattern matcher? I could not figure out how to group in the below code.
Pattern p = Pattern.compile("(?=[ABC])");
Matcher m = p.matcher(s);
List<String> matches = new ArrayList<>();
while (m.find()) {
matches.add(m.group());
}
Also suppose I have few characters before first occurance of A, B or C and I want to combine with first element in ArrayList. ,,A..
Appreciate the help.
String[] result = Pattern.compile("(?=[ABC])").split(s, 0);?