-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature request: extend Match class to access group's start/end index #45486
Comments
The reason that functionality is not available is that it's not possible in JavaScript. |
@lrhn I don't know JS very well, but, maybe, something from https://stackoverflow.com/questions/1985594/how-to-find-indices-of-groups-in-javascript-regular-expressions-match could be useful? If it is not possible, please, close the task |
@yan-zaitsev, seems like this is a question for @lrhn, isn't it? |
I have thought about whether we could reasonably make capture group indices available in JS before, and have not found a good way. So, if you really, really want to know the indices of RegExp capture groups, you'll have to massage your RegExp yourself to capture "everything before the capture" as well. It's not something we can automate in an efficient and consistent way. So, closing as not planned (until JS changes to make the information available). |
@lrhn RegExp Match Indices are at Stage 4 in TC-39 (see https://github.com/tc39/proposal-regexp-match-indices) and are shipping in M91 and FF Nightly and Safari preview. So maybe you could reconsider closing this issue. |
That's great news. We'll still have to decide when we think the browsers we support are sufficiently updated to make the switch |
Proof of concept: https://dart-review.googlesource.com/c/sdk/+/212582 (Definitely needs more design work, and then we need to decide whether we think it's well-enough supported on the web). |
Duplicate of #42307 |
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:
It will return me
List<Match>
which I could render in UI.Problem
When I want to use more complex Regex with groups:
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:
The text was updated successfully, but these errors were encountered: