JS: RegExp.prototype
What is RegExp.prototype
RegExp.prototype
is the value of the property key "prototype"
of the function RegExp
. 〔see RegExp Object〕
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
- test
- exec
toString
[ Symbol.match ]
JS2015[ Symbol.replace ]
JS2015[ Symbol.search ]
JS2015[ Symbol.split ]
JS2015
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 Flag〕 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 occurrences. When global flagg
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: RegExp Tutorial
- JS: Regex Functions
- JS: RegExp Syntax
- JS: RegExp Flag
- JS: Regex Replace String Dollar Sign
- JS: Regex Replace Function Args
- JS: RegExp Object
- 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