JavaScript: RegExp.prototype

By Xah Lee. Date: . Last updated: .

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

[see RegExp Object]

console.log(
 RegExp.hasOwnProperty ( "prototype" ) ); // true

Type

Type of RegExp.prototype is Object .

console.log(
 typeof RegExp.prototype === "object"
); // true

console.log(
 Object.prototype.toString.call( RegExp.prototype ) === "[object Object]"
); // true

Parent

Parent of RegExp.prototype is Object.prototype .

console.log(
 Reflect.getPrototypeOf ( RegExp.prototype ) === Object.prototype
); // true

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.

console.log(
 Reflect.getPrototypeOf ( /abc/ ) === RegExp.prototype
); // true

Properties

Function Properties

Value Properties

source
Value is the regex pattern as string.
global
Value is true/false, corresponds to presence of flag g in regex. [see RegExp Flags]
ignoreCase
Value is true/false, corresponds to presence of flag i in regex.
multiline
Value is true/false, corresponds to presence of flag m in regex.
unicode
Value is true/false, corresponds to presence of flag u in regex. (JS2015)
sticky
Value is true/false, corresponds to presence of y in regex. (JS2015)
flags
a string of all on flags. Sample value: "gimuy" (JS2015)
lastIndex
A index for the target string, for regex function to begin match. It is automatically set by regex functions, usually when global flag g is on, to allow you to do a loop to find all occurances. 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

JS in Depth
XAH  BUY NOW

JS in Depth

JS Obj Ref

DOM


JS Obj Ref

RegExp

prototype

Syntax

misc