JS: RegExp.prototype

By Xah Lee. Date: . Last updated: .

What is RegExp.prototype

RegExp.prototype is the value of the property key "prototype" of the function RegExp.

RegExp.hasOwnProperty("prototype")

Type

Type of RegExp.prototype is Object .

typeof RegExp.prototype === "object"

Parent

Parent of RegExp.prototype is Object.prototype .

Reflect.getPrototypeOf(RegExp.prototype) === Object.prototype

Purpose

Purpose of RegExp.prototype is to provide methods and properties useful for all regexp instances.

RegExp.prototype is the parent of all RegExp instances.

Reflect.getPrototypeOf(/abc/) === RegExp.prototype

Properties

Function Properties

Value Properties

RegExp.prototype.source
Value is the regex pattern as string.
RegExp.prototype.global
Value is true/false, corresponds to presence of RegExp Flag g in regex.
RegExp.prototype.ignoreCase
Value is true/false, corresponds to presence of RegExp Flag i in regex.
RegExp.prototype.multiline
Value is true/false, corresponds to presence of RegExp Flag m in regex.
RegExp.prototype.unicode
Value is true/false, corresponds to presence of RegExp Flag u in regex. (new in JS: ECMAScript 2015)
RegExp.prototype.sticky
Value is true/false, corresponds to presence of y in regex. (new in JS: ECMAScript 2015)
RegExp.prototype.flags
a string of all on RegExp Flags. Sample value: "gimuy" (new in JS: ECMAScript 2015)
RegExp.prototype.lastIndex
A index for the target string, for regex function to begin match. It is automatically set by regex functions, usually when global RegExp Flag g is on, to allow you to do a loop to find all occurrences. When global flag g is off, this value is 0. When it is on, the regex function, when finished execution, advanced the index by set the index to end position of a match (or 0 when no more match), so next call will start search from there.
const gx = /\d/g;
console.log(gx.lastIndex); // 0
console.log(gx.exec("a2cd3f")); // [ "2" ]
console.log(gx.lastIndex); // 2
console.log(gx.exec("a2cd3f")); // [ "3" ]
console.log(gx.lastIndex); // 5
〔see RegExp.prototype.exec

JavaScript. Regular Expression