Description
dart --version: Dart SDK version: 2.10.5 (stable) (Tue Jan 19 13:05:37 2021 +0100) on "macos_x64"
My feature request is to extend
Match class: https://github.com/dart-lang/sdk/blob/master/sdk/lib/core/pattern.dart
so it will be possible to get start/end position of founded groups.
My case:
I want to find some substring in text and bold it in UI for user so he will see entered search text in founded texts.
I am doing it using simple Regex:
final stringRanges = RegExp("${RegExp.escape(searchInput)}", caseSensitive: false, unicode: true)
.allMatches(text)
.toList();
It will return me List<Match>
which I could render in UI.
Problem
When I want to use more complex Regex with groups:
final stringRanges = RegExp("begin(${RegExp.escape(searchInput)})end", caseSensitive: false, unicode: true)
.allMatches(text)
.toList();
At this moment, stringRanges
contains more complex Match with groups. I want to parse every group in match with its start/end positions.
Solution
Match class has method String? group(int group);
to get string value of founded group.
I will happy to have api like Match? groupMatch(int group);
to get more information about single group.
For me it will be enough to have simpler api:
class StringRange {
int start;
int end;
StringRange(this.start, this.end);
}
abstract class Match {
...
StringRange? groupRange(int group);
...
}