將一個字串分解為所有可變長度的子字串

與已知長度示例相同,但將長度插入正規表示式:

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