Open In App

JavaScript RegExp sticky Property

JavaScript RegExp sticky property is used to check whether the ‘s’ flag is set or not. If the ‘s’ flag is set then this property returns true else false.

Syntax: 



RegExpobj.sticky

Return Type: A boolean value.

Example 1: This example checks whether ‘y’ flag is present or not and prints it on the console.






function stickyProp() {
    let regex = new RegExp(/[a-d]/, 'd');
 
    console.log(regex.sticky);
}
 
stickyProp();

Output
false

Example 2: This example checks whether ‘y’ flag is present or not.




function stickyProp() {
    let regex = new RegExp(/[a-d]/, 'y');
 
    if (regex.sticky) {
        console.log("y flag is present");
    } else {
        console.log("y flag is absent");
    }
}
 
stickyProp();

Output
y flag is present

Supported Browsers:

We have a complete list of JavaScript RegExp expressions, to check those please go through this JavaScript RegExp Reference article.

Article Tags :