As of Firefox 88, we will support match indices in RegExps.

Use case:

Match Indices provide additional information about the start and end indices of 
captured substrings relative to the start of the input string. This information 
is only provided if the regexp has the /d flag set. For example:

let re = /A*(B)/d;
let result = re.exec("xxxAABxxx");
// The match begins at index 3 and ends at index 6
// result.indices[0][0] === 3;
// result.indices[0][1] === 6;
// The capture group containing 'B' begins at index 5 and ends at index 6
// result.indices[1][0] === 5;
// result.indices[1][1] === 6;

Match indices are currently Stage 3.

Bug: 
https://bugzilla.mozilla.org/show_bug.cgi?id=1519483

Standard: 
https://github.com/tc39/proposal-regexp-match-indices

Platform coverage:
All, no pref

DevTools bug:
N/A

Other browsers:
Implemented in JSC: https://bugs.webkit.org/show_bug.cgi?id=202475
Implemented in V8 behind a pref: 
https://bugs.chromium.org/p/v8/issues/detail?id=9548

Testing: 
There are test262 tests covering this feature:
https://github.com/tc39/test262/tree/main/test/built-ins/RegExp/match-indices

Secure contexts:
This is a JS language feature and is therefore present in all contexts.

_______________________________________________
dev-platform mailing list
dev-platform@lists.mozilla.org
https://lists.mozilla.org/listinfo/dev-platform

Reply via email to