Mark specific RegExp group, not whole match
See original GitHub issueIs your feature request related to a problem? Please describe. Let’s say you have a string: “1) You have 12 points.” And you want to mark the number. But you don’t want to mark all numbers, only the one before word “points”.
Describe the solution you’d like
One solution could be adding a groupNumber: number
to the options
object which would specify a group from the regexp.
So one could write a regexp like /(\d+) points/
and pass 0
as a group number.
Additional context
Test in console:
"1) You have 12 points.".match(/(\d+) points/)[1]
PS: thank you for making this amazing library!
Issue Analytics
- State:
- Created 3 years ago
- Comments:5
Top Results From Across the Web
What is a non-capturing group in regular expressions?
The non-capturing group (?...) does not remove any characters from the original full match, it only reorganises the regex visually to the ...
Read more >Capturing groups - The Modern JavaScript Tutorial
The method str.match(regexp) , if regexp has no flag g , looks for the first match and returns it as an array: At...
Read more >2.4: Regular Expressions: Capturing Groups - YouTube
In this video I discuss capturing parentheses and how they are used to create numbered groups that referenced in a find / replace...
Read more >The Question Mark Makes the Preceding Token Optional
The question mark gives the regex engine two choices: try to match the part the question mark applies to, or do not try...
Read more >Non-Capturing Regex Groups in Java - Baeldung
Although they don't save the matched character sequence, non-capturing groups can alter pattern matching modifiers within the group. Some non- ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Wow, the time flies 😃 I would still like to see a group number support. But no rush, I’m busy myself 😃
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.