groupPureOrLinkCapture function
groupPureOrLink is patterns like this (()|()|())+?
in case below
r'exec(((( a)|( b)|( c))+?)| -name((( d)|( e)|( f))+?))+'
replaceGroupIndexs is {
3 : 4,5,6
,
8 : 9,10,11
}
Implementation
List<String?>? groupPureOrLinkCapture(
String string, String pattern, Map<int, List<int>> pureOrLinkGroupIndexs) {
assert(pattern.contains('?') == true);
var m = RegExp(pattern).matchAsPrefix(string);
List<String?>? groups;
while (m != null) {
groups = groups ?? m.groups(genIndices(m.groupCount));
pureOrLinkGroupIndexs.entries.forEach((MapEntry<int, List<int>> replaced) {
var rplc = m!.group(replaced.key);
if (rplc != null) {
replaced.value.forEach((refreshIndex) {
groups![refreshIndex] =
groups[refreshIndex] ?? m!.group(refreshIndex);
});
string = string.replaceFirst(rplc, '');
}
});
m = RegExp(pattern).matchAsPrefix(string);
}
return groups;
}