RegExp.prototype.hasIndices
The hasIndices
property indicates whether or not the "d
" flag is used with the regular expression. hasIndices
is a read-only property of an individual regular expression instance.
Property attributes of RegExp.prototype.hasIndices |
|
---|---|
Writable | no |
Enumerable | no |
Configurable | yes |
Description
The value of hasIndices
is a Boolean
and true
if the "d
" flag was used; otherwise, false
. The "d
" flag indicates that the result of a regular expression match should contain the start and end indices of the substrings of each capture group.
You cannot change this property directly.
Examples
Using hasIndices
const str1 = 'foo bar foo';
const regex1 = new RegExp('foo', 'gd');
console.log(regex1.hasIndices); // Output: true
console.log(regex1.exec(str1).indices[0]); // Output: Array [0, 3]
console.log(regex1.exec(str1).indices[0]); // Output: Array [8, 11]
const str2 = 'foo bar foo';
const regex2 = new RegExp('foo');
console.log(regex2.hasIndices); // Output: false
console.log(regex2.exec(str2).indices); // Output: undefined
Specifications
Specification |
---|
RegExp Match Indices # sec-get-regexp.prototype.hasIndices |
Browser compatibility
BCD tables only load in the browser