-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Description
When executing a RegExp, groups are returned as a map of Strings. However, for some use cases it is really important to get the index of where these groups are in the input string, rather than just the text.
For example, I have the following code:
final pattern = RegExp('(?:(?<=[^\\\\])|^){{(\\w*)}}');
final match = pattern.firstMatch('A captured word I {{capture}}');
print(match.group(1));This correctly prints 'capture'. However, there is no way to know (at least, in my use case where I am being fed regexps from an external file) whether this group is referring to 'capture' in the source string at span 2-10 or 20-28. In this case the answer is 20-28 and that is what I would like to be able to retrieve.
In other languages:
In python you would call match.span(1) which would return a tuple of the start and end position. In Dart this could be replaced with an object.
In JavaScript this is not supported, meaning this feature would probably not be supported in dart2js.