I need to split a string at every i-th and j-th character, where i and j can change according to input parameters. If for example i have an input
String s = "1234567890abcdef";
int i = 2;
int j = 3;
I want my output to be an array of:
[12, 345, 67, 890, ab, cde, f]
I found a compact regex to split at every n-th char. Example for n = 3 using "(?<=\\G...)" or "(?<=\\G.{3})"
String s = "1234567890abcdef";
int n = 3;
System.out.println(Arrays.toString(s.split("(?<=\\G.{"+n+"})")));
//output: [123, 456, 789, 0ab, cde, f]
How to modify the above regex to split at every 2nd and 3rd char alternately?
A naive chaining like "(?<=\\G.{2})(?<=\\G.{3})" did not work.
