Open In App

JavaScript RegExp sticky Property

Last Updated : 01 Aug, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

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.

Javascript




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.

Javascript




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:

  • Chrome 49
  • Edge 13
  • Firefox 3
  • Opera 36
  • Safari 10

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


Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads