Let's say I have a regular expression /([a-z]+):([0-9]+)/
and a sample text hello:123
.
Is there a way for me to execute this expression so that it returns all capturing groups along with positions for each group?
For example the result should be something like [["hello", 0], ["123", 6]]
.
As far as I found, the regular expression only returns the position for the whole match, which is not enough for what I need :( Thanks!
UPDATE:
In PHP, this can be achieved with PREG_OFFSET_CAPTURE
flag, but I need the same behaviour for JS
SOLUTION:
In this thread Get index of each capture in a JavaScript regex there is a class MultiRegExp2
which allows for this functionality https://github.com/valorize/MultiRegExp2