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.

console.assert(Object.hasOwn(RegExp, "prototype") === true);

Type

Type of RegExp.prototype is Object .

console.assert(typeof RegExp.prototype === "object");

Parent

Parent of RegExp.prototype is Object.prototype .

console.assert(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.

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

Properties

Function Properties

Value Properties

RegExp.prototype.source

Value is the regex pattern as string.

const xre = /[aeiou]/g;
console.log("something".match(xre));
// [ "o", "e", "i" ]
console.log(xre.source);
// [aeiou]
RegExp.prototype.flags

(new in ECMAScript 2015)

A string of all regex flags that are on. e.g. "gim"

const xre = /[aeiou]/gi;
console.log("SOMETHING".match(xre));
// [ "O", "E", "I" ]
console.log(xre.flags);
// gi
RegExp.prototype.lastIndex

Regex flags

These are boolean values corresponding to presence of regex flag in a regex object.

JavaScript. Regular Expression