2.3.2 [ECMA-262/6] Section 21.2.4 Properties of the RegExp Constructor

E0001: The RegExp constructor has additional properties that represent the first nine groups of the last successful match

The specification states:

 21.2.4 Properties of the RegExp Constructor
  
     The value of the [[Prototype]] internal slot of the RegExp constructor is the 
     intrinsic object %FunctionPrototype%.
  
     ... the RegExp constructor has the following properties:

IE11 Mode and EdgeHTML Mode (All versions)

The RegExp constructor has additional properties, $1, $2, ..., and $9, that represent the first nine groups of the last successful match. Before a successful match, each property is set to the empty string. For each group of the match (up to nine maximum), the corresponding property is set to a value that represents the group. For example:

    var re = /(a|b)(c|d)/;

    // RegExp.$1 === ''

    // RegExp.$2 === ''

    // RegExp.$3 === ''

    // ...

    // RegExp.$9 === ''

    re.exec('ac'); // Successful match

    // RegExp.$1 === 'a'

    // RegExp.$2 === 'c'

    // RegExp.$3 === ''

    // ...

    // RegExp.$9 === ''

    re.exec('yz'); // No match

    // $1-$9 are same as before

    // RegExp.$1 === 'a'

    // RegExp.$2 === 'c'

    // RegExp.$3 === ''

    // ...

    // RegExp.$9 === ''

    re.exec('bd'); // Successful match

    // $1-$2 are now different

    // RegExp.$1 === 'b'

    // RegExp.$2 === 'd'

    // RegExp.$3 === ''

    // ...

    // RegExp.$9 === ''

These properties are data properties and have the following attributes:

    {"writable":true,"enumerable":true,"configurable":false}

Even though the [[Writable]] attribute is true, the properties are read-only and it is not possible to change their values directly.

E0002: The RegExp constructor has a property named input that represents the input string of the last successful match

The specification states:

 21.2.4 Properties of the RegExp Constructor
  
     The value of the [[Prototype]] internal slot of the RegExp constructor is the 
     intrinsic object %FunctionPrototype%.
  
     ... the RegExp constructor has the following properties:

IE11 Mode and EdgeHTML Mode (All versions)

The RegExp constructor has a property named input that represents the input string of the last successful match. Before a successful match, it is set to the empty string. For example:

    var re = /a|c/

    // RegExp.input === ''

    re.exec('az')

    // RegExp.input === 'az'

    re.exec('bz')

    // RegExp.input === 'az'

    re.exec('cz')

    // RegExp.input === 'cz'

This is a data property and has the following attributes:

    {"writable":true,"enumerable":true,"configurable":false}

Even though the [[Writable]] attribute is true, the property is read-only and it is not possible to change its value directly.

RegExp constructor has a property named $_ which behaves the same way as the input property but has the following attributes:

    {"writable":true,"enumerable":false,"configurable":false}

E0003: The RegExp constructor has a property named lastMatch that holds the matched substring for the last successful match

The specification states:

 21.2.4 Properties of the RegExp Constructor
  
     The value of the [[Prototype]] internal slot of the RegExp constructor is the 
     intrinsic object %FunctionPrototype%.
  
     ... the RegExp constructor has the following properties:

IE10 Mode and EdgeHTML Mode (All versions)

The RegExp constructor has a property named lastMatch that holds the matched substring for the last successful match. Before a successful match it is set to the empty string. For example:

    var re = /a|c/

    // RegExp.lastMatch === ''

    re.exec('az')

    // RegExp.lastMatch === 'a'

    re.exec('bz')

    // RegExp.lastMatch === 'a'

    re.exec('cz')

    // RegExp.lastMatch === 'c'

lastMatch is a data property and has the following attributes:

    {"writable":true,"enumerable":true,"configurable":false}

Even though the [[Writable]] attribute is true, lastMatch is read-only and it is not possible to change its value directly.

The RegExp constructor has a property named $& that behaves the same as lastMatch but has the following attributes:

    {"writable":true,"enumerable":false,"configurable":false}

E0004: The RegExp constructor has a property named lastParen that represents the last group from the last successful match

The specification states:

 21.2.4 Properties of the RegExp Constructor
  
     The value of the [[Prototype]] internal slot of the RegExp constructor is the 
     intrinsic object %FunctionPrototype%.
  
     ... the RegExp constructor has the following properties:

IE11 Mode and EdgeHTML Mode (All versions)

The RegExp constructor has a property named lastParen that represents the last group from the last successful match. Before a successful match, it is set to the empty string. For example:

    var re = /(a|b)(c|d)?/

    // RegExp.lastParen === ''

    re.exec('ac')

    // RegExp.lastParen === 'c'

    re.exec('z')

    // RegExp.lastParen === 'c'

    re.exec('bd')

    // RegExp.lastParen === 'd'

lastParen is a data property and has the following attributes:

    {"writable":true,"enumerable":true,"configurable":false}

Even though the [[Writable]] attribute is true, lastParen is read-only and it is not possible to change its value directly.

The RegExp constructor has another property called $+ which behaves the same as lastParen but has the following attributes:

    {"writable":true,"enumerable":false,"configurable":false}

E0005: The RegExp constructor has a property named leftContext that holds the substring of the input string that is to the left of the matched substring

The specification states:

 21.2.4 Properties of the RegExp Constructor
  
     The value of the [[Prototype]] internal slot of the RegExp constructor is the 
     intrinsic object %FunctionPrototype%.
  
     ... the RegExp constructor has the following properties:

IE11 Mode and EdgeHTML Mode (All versions)

The RegExp constructor has a property named leftContext that holds the substring of the input string that is to the left of the matched substring of the last successful match. Before a successful match, leftContext is set to the empty string. For example:

    var re = /world/g

    // RegExp.leftContext === ''

    re.exec('Hello world')

    // RegExp.leftContext === 'Hello '

    re.exec('failure')

    // RegExp.leftContext === 'Hello '

    re.exec('Another hello world')

    // RegExp.leftContext === 'Another hello '

leftContext is a data property and has the following attributes:

    {"writable":true,"enumerable":true,"configurable":false}

Even though the [[Writable]] attribute is true, leftContext is read-only and cannot be changed directly.

The RegExp constructor also has a property named $` which behaves the same as leftContext but has the following attributes:

    {"writable":true,"enumerable":false,"configurable":false}

E0006: The RegExp constructor has a property named rightContext that holds the substring of the input string that is to the right of the matched substring

The specification states:

 21.2.4 Properties of the RegExp Constructor
  
     The value of the [[Prototype]] internal slot of the RegExp constructor is the 
     intrinsic object %FunctionPrototype%.
  
     ... the RegExp constructor has the following properties:

IE11 Mode and EdgeHTML Mode (All versions)

The RegExp constructor has a property named rightContext that holds the substring of the input string that is to the right of the matched substring of the last successful match. Before a successful match, rightContext is set to the empty string. For example:

    var re = /test/g

    // RegExp.rightContext === ''

    re.exec('test right')

    // RegExp.rightContext === ' right'

    re.exec('failure')

    // RegExp.rightContext === ' right'

    re.exec('test right another')

    // RegExp.rightContext === ' right another'

rightContext is a data property and has the following attributes:

    {"writable":true,"enumerable":true,"configurable":false}

Even though the [[Writable]] attribute is true, rightContext is read-only and cannot be changed directly.

The RegExp constructor also has a property named $' which behaves the same as rightContext but has the following attributes:

    {"writable":true,"enumerable":false,"configurable":false}

E0007: The RegExp constructor has a property named index whose value is the starting index of the matched substring of the last successful match

The specification states:

 21.2.4 Properties of the RegExp Constructor
  
     The value of the [[Prototype]] internal slot of the RegExp constructor is the 
     intrinsic object %FunctionPrototype%.
  
     ... the RegExp constructor has the following properties:

IE11 Mode and EdgeHTML Mode (All versions)

The RegExp constructor has a property named index whose value is the starting index of the matched substring of the last successful match. Before a successful match, it is set to -1. For example:

    var re = /world/g

    // RegExp.index === -1

    re.exec('Hello world')

    // RegExp.index === 6

    re.exec('failure')

    // RegExp.index === 6

    re.exec('Another hello world')

    // RegExp.index === 14

index is a data property and has the following attributes:

    {"writable":true,"enumerable":false,"configurable":false}

Even though the [[Writable]]attribute is true, index is read-only and cannot be changed directly.