JS: RegExp.prototype
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
- JS: RegExp.prototype.test
- JS: RegExp.prototype.exec
RegExp.prototype.toStringRegExp.prototype[Symbol.match]JS2015RegExp.prototype[Symbol.replace]JS2015RegExp.prototype[Symbol.search]JS2015RegExp.prototype[Symbol.split]JS2015
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
gin regex. RegExp.prototype.ignoreCase-
Value is true/false, corresponds to presence of RegExp Flag
iin regex. RegExp.prototype.multiline-
Value is true/false, corresponds to presence of RegExp Flag
min regex. RegExp.prototype.unicode-
Value is true/false, corresponds to presence of RegExp Flag
uin regex. (new in JS: ECMAScript 2015) RegExp.prototype.sticky-
Value is true/false, corresponds to presence of
yin 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
gis on, to allow you to do a loop to find all occurrences. When global flaggis 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.
〔see RegExp.prototype.exec〕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
JavaScript. Regular Expression
- JS: RegExp Tutorial
- JS: Regex Functions
- JS: Create Regex Object
- JS: RegExp Syntax
- JS: RegExp Flag
- JS: Regex Replace String Dollar Sign
- JS: Regex Replace Function Args
- JS: RegExp (class)
- JS: RegExp Constructor
- JS: RegExp.prototype
- JS: String.prototype.search
- JS: String.prototype.match
- JS: String.prototype.matchAll
- JS: String.prototype.replace
- JS: String.prototype.replaceAll
- JS: RegExp.prototype.test
- JS: RegExp.prototype.exec