Javascript RegExp Instance Properties

Introduction

Each instance of RegExp has the following properties that allow you to get information about the pattern:

RegExp Instance Properties Value Type Meaning
global Boolean indicating whether the g flag has been set.
ignoreCaseBoolean indicating whether the i flag has been set.
unicode Boolean indicating whether the u flag has been set.
sticky Booleanindicating whether the y flag has been set.
lastIndexinteger indicating the character position where the next match will be attempted in the source string. This value always begins as 0.
multilineBoolean indicating whether the m flag has been set.
source string source of the regular expression. in literal form without opening and closing slashes.
flagsstring flags of the regular expression. in literal form without opening and closing slashes.

These properties are helpful in identifying aspects of a regular expression.

let pattern1 = /\[bc\]at/i;

console.log(pattern1.global); // false 
console.log(pattern1.ignoreCase); // true 
console.log(pattern1.multiline); // false 
console.log(pattern1.lastIndex); // 0 
console.log(pattern1.source); // "\[bc\]at" 
console.log(pattern1.flags); // "i" 

let pattern2 = new RegExp("\\[bc\\]at", "i");

console.log(pattern2.global); // false 
console.log(pattern2.ignoreCase); // true 
console.log(pattern2.multiline); // false 
console.log(pattern2.lastIndex); // 0 
console.log(pattern2.source); // "\[bc\]at" 
console.log(pattern2.flags); // "i" 



PreviousNext

Related