将一个字符串分解为所有可变长度的子字符串

与已知长度示例相同,但将长度插入正则表达式:

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