JS: RegExp.prototype

By Xah Lee. Date: . Last updated: .

What is RegExp.prototype

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

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.