Java Language Break a string up into substrings all of variable length


Example

Same as the known length example, but insert the length into regex:

int length = 5;
String[] parts = str.split("(?<=\\G.{" + length + "})");