JS: RegExp.prototype
RegExp.prototype
is the value of the property key "prototype"
of the function RegExp
.
[see JS: RegExp Object]
console.log( RegExp.hasOwnProperty ( "prototype" ) ); // true
Type
Type of RegExp.prototype
is object.
[see JS: Value Types]
// type of RegExp.prototype console.log ( typeof RegExp.prototype === "object" ); // true console.log ( Object.prototype.toString.call( RegExp.prototype ) === "[object Object]" ) // true
Parent
Parent of RegExp.prototype
is Object.prototype
.
// parent of RegExp.prototype console.log ( Object.getPrototypeOf ( RegExp.prototype ) === Object.prototype ); // true
[see JS: Prototype and Inheritance]
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.log ( Object.getPrototypeOf ( /abc/ ) === RegExp.prototype ); // true
Properties
Function Properties
- RegExp.prototype.test
- RegExp.prototype.exec
RegExp.prototype.toString ( )
RegExp.prototype [ Symbol.match ]
ES2015RegExp.prototype [ Symbol.replace ]
ES2015RegExp.prototype [ Symbol.search ]
ES2015RegExp.prototype [ Symbol.split ]
ES2015
Value Properties
RegExp.prototype.source
RegExp.prototype.global
RegExp.prototype.ignoreCase
RegExp.prototype.multiline
RegExp.prototype.lastIndex
RegExp.prototype.flags
ES2015RegExp.prototype.sticky
ES2015RegExp.prototype.unicode
ES2015
Function Properties
RegExp.prototype [ Symbol.match ]
ECMAScript® 2016 Language Specification#sec-regexp.prototype-@@match
RegExp.prototype [ Symbol.replace ]
ECMAScript® 2016 Language Specification#sec-regexp.prototype-@@replace
RegExp.prototype [ Symbol.search ]
ECMAScript® 2016 Language Specification#sec-regexp.prototype-@@search
RegExp.prototype [ Symbol.split ]
ECMAScript® 2016 Language Specification#sec-regexp.prototype-@@split
Value Properties
Property | Read Only | Meaning |
---|---|---|
source | read only | the regex pattern as string. |
global | read only | true if there's the global flag g in regex. |
ignoreCase | read only | true if there's the ignore case flag i in regex. |
multiline | read only | true if there's the multi-line flag m in regex. |
unicode | read only | true if there's the unicode flag u in regex. ES2015 |
sticky | read only | true if there's the sticky flag y in regex. ES2015 |
flags | read only | Returns a string of all used flags. e.g. "gimuy" ES2015 |
Property | Read Only | Meaning |
---|---|---|
lastIndex | read/write | When global flag g is used, the value is the position of end of last match. Next invocation of the method with the same RegExp object will start from here. (you may want to reset this to 0 in a loop.) When global flag is not used, this value is always 0. |
[see JS: RegExp Syntax]
Example:
// example of RegExp.prototype value properties const txt = "love cats"; const regex = new RegExp("cat", "ig"); const result = regex.exec(txt); // print RegExp properties console.log ( regex.source === "cat"); // true console.log ( regex.global); // true console.log ( regex.ignoreCase); // true console.log ( regex.multiline); // false console.log ( regex.flags === "gi"); // true console.log ( regex.lastIndex); // 8 // print result console.log ( result); // [ 'cat', index: 5, input: 'love cats' ]
RegExp Result Object Properties
Property | Meaning |
---|---|
index | the beginning position of first occurrence. |
input | the input string. |
// example of RegExp result properties const myText = 'a x1 X2 c'; const myRe = new RegExp('\\w\\d+', "ig"); const myResult = myRe.exec(myText); // print result properties console.log ( myResult.index); // 2 console.log ( myResult.input); // a x1 X2 c
Reference
ECMAScript® 2016 Language Specification#sec-regexp.prototype
RegExp Topic
String Topic
- JS: String Overview
- JS: Template String
- JS: String Object
- JS: String.prototype
- JS: String Code Unit vs Code Point
- JS: String Escape Sequence
- JS: Unicode Escape Sequence
- JS: Source Code Encoding
- JS: Allowed Characters in Identifier
- JS: Convert String to Number
- JS: Encode URL, Escape String
- JS: Format Number
- JS: JSON
JS Object Reference
Ask me question on patreon