THE WORLD'S LARGEST WEB DEVELOPER SITE
HTMLCSSJAVASCRIPTSQLPHPBOOTSTRAPJQUERYANGULARXML
 

JavaScript RegExp g Modifier

RegExp Object Reference JavaScript RegExp Object

Example

Do a global search for "is":

var str = "Is this all there is?";
var patt1 = /is/g;

The marked text below shows where the expression gets a match:

Is this all there is?
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

Internet Explorer Firefox Opera Google Chrome Safari

The g modifier is supported in all major browsers.


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;

The marked text below shows where the expression gets a match:

Is this all there is?
Try it yourself »

RegExp Object Reference JavaScript RegExp Object