getPatterns function
This method returns a map
with a list of substrings matched.
The key is that by the name of
patternName
.
Implementation
Map<String, List<String>> getPatterns(
String patternName, String subject, RegExp regex) {
Map<String, List<String>> result = {};
Iterable<Match> matchObj = regex.allMatches(subject);
List<String> imList = [];
for (int i = 0; i < matchObj.length; i++) {
Match myMatch = matchObj.elementAt(i);
int actualLength = myMatch.groupCount + 1;
for (int x = 0; x < actualLength; x++) {
String subString = myMatch.group(x).toString();
imList.add(subString);
}
}
result.addAll({patternName: imList});
return result;
}