Open In App
Related Articles

JavaScript RegExp global Property

Improve Article
Improve
Save Article
Save
Like Article
Like

The global Property in JavaScript is used to specify whether the “g” modifier is set or not. If the “g” modifier is set then this property returns true else false.

Syntax: 

RegexObj.global

Return Value: It returns true if g modifier is set, else false.

Example 1: This example checks if the regular expression contains g Modifier or not.  

Javascript




function geek() {
    let regex = new RegExp('foo', 'g');
    console.log(regex.global);
}
geek()


Output

true

Example 2: This example checks if the regular expression contains g Modifier or not.  

Javascript




function geek() {
    let regex = /[a-d]/;
    let str =
        "GeeksforGeeks\n" +
        "is the computer\n" +
        "science portal for geeks.";
 
    if (regex.global) {
        console.log("g Modifier is present");
    } else {
        console.log("g Modifier is absent.");
    }
}
geek()


Output

g Modifier is absent.

Supported Browsers: The browsers supported by JavaScript global Property are listed below: 

  • Google Chrome
  • Apple Safari
  • Mozilla Firefox
  • Opera
  • Internet Explorer

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

Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!

Last Updated : 30 May, 2023
Like Article
Save Article
Previous
Next
Similar Reads
Complete Tutorials