expand function
Implementation
List<String> expand(String input) {
final matches = RegExp(r'\[(.*?)\]').firstMatch(input);
if (matches == null) return [input];
final results = <String>[];
final range = matches.group(1)!.split('-');
// Check if the range is numeric or character
if (range[0].codeUnitAt(0) >= 48 && range[0].codeUnitAt(0) <= 57) {
int lowerBound = int.parse(range[0]);
int upperBound = int.parse(range[1]);
for (var i = lowerBound; i <= upperBound; i++) {
var newInput = input.replaceFirst(matches.group(0)!, i.toString());
results.addAll(expand(newInput));
}
} else {
int lowerBound = range[0].codeUnitAt(0);
int upperBound = range[1].codeUnitAt(0);
for (var i = lowerBound; i <= upperBound; i++) {
var expanded = String.fromCharCode(i);
var newInput = input.replaceFirst(matches.group(0)!, expanded);
results.addAll(expand(newInput));
}
}
return results;
}