Open In App

JavaScript RegExp flags Property

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

JavaScript RegExp flags property is an accessor property that returns the flags being used in the Regular Expression. The flags are returned in alphabetical order and the result is a concatenation of strings.

Syntax:

Regexobj.flags

Return Type: A string containing flags used in Regular Expression.

Example 1: This example prints the flags used in Regular Expression on the console.

Javascript




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


Output

ms

Example 2: This example prints the flags used in Regular Expression.

Javascript




function flags_prop() {
    let regex =new RegExp(/[a-d]/, "sd");
     
    console.log("The flags are: " + regex.flags);
}
 
flags_prop();


Output

The flags are: ds

Supported Browsers:

  • Chrome 49
  • Edge 79
  • Firefox 37
  • Opera 39
  • Safari 9

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