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

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;

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