Open6
正規表現のキャプチャグループについても index が取得したい

npm install multi-regexp2

tsconfig.json
{
"baseUrl": "./",
"paths": {
"multi-regexp2": [
"src/types/multi-regexp2.d.ts"
],
},
...
}

src/types/multi-regexp2.d.ts
export default class MultiRegExp2 {
constructor(baseRegExp: RegExp);
execForAllGroups(str: string, includeFullMatch: boolean): {match: string, start: number, end: number}[]
execForGroup(str: string, group: number): {match: string, start: number, end: number}
}

mycode.ts
import MultiRegExp2 from 'multi-regexp2'
const regex = /a(?: )bc(def(ghi)xyz)/g;
const regex2 = new MultiRegExp2(regex);
const matches = regex2.execForAllGroups('ababa bcdefghixyzXXXX');
console.log(matches);

でもそもそもこのパッケージは capture グループ使えない。。。