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

  • RegExp.prototype[Symbol.match]
  • RegExp.prototype[Symbol.replace]
  • RegExp.prototype[Symbol.search]
  • RegExp.prototype[Symbol.split]

These are the hidden methods that many of the regex methods actually call. These are created so that it can be customized by overriding their values. They were added in ECMAScript 2015 .

Value Properties

RegExp.prototype.source

A Getter Property. Value is the regex pattern as string of the given regex object.

console.assert(
 /[aeiou]/g.source === "[aeiou]",
);
RegExp.prototype.flags

(new in ECMAScript 2015)

A Getter Property. Value is a string of all regex flags that are set, on the given regex object. e.g. "gim"

result is in alphabetical order.

const rgx = /abc/gi;
console.assert(rgx.flags === "gi");

Regex flags

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

RegExp.prototype.ignoreCase
flag i. see JS: Regex Flags
RegExp.prototype.multiline
flag m. see JS: Regex Flags
RegExp.prototype.dotAll
JS: Regex Flag s (dotAll)
RegExp.prototype.global
JS: Regex Flag g (global)
RegExp.prototype.hasIndices
JS: Regex Flag d (hasIndices)
RegExp.prototype.sticky
JS: Regex Flag y (sticky)
RegExp.prototype.unicode
JS: Regex Flag u (unicode)
RegExp.prototype.unicodeSets
JS: Regex Flag v (unicodeSets)