JavaScript RegExp g Modifier
Example
Do a global search for "is":
var str = "Is this all there is?";
var patt1 = /is/g;
Try it Yourself »
Definition and Usage
The g modifier is used to perform a global match (find all matches rather than stopping after the first match).
Tip: To perform a global, case-insensitive search, use this modifier together with the "i" modifier.
Tip: Use the global property to specify whether or not the g modifier is set.
Browser Support
Expression | |||||
---|---|---|---|---|---|
g | Yes | Yes | Yes | Yes | Yes |
Syntax
new RegExp("regexp", "g")
or simply:
/regexp/g
More Examples
Example
Do a global, case-insensitive search for "is":
var str = "Is this all there is?";
var patt1 = /is/gi;
Try it Yourself »