X
HOME HTML CSS JAVASCRIPT SQL PHP JQUERY XML ASP.NET MORE...
REFERENCES | EXAMPLES | FORUM | ABOUT

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

Your suggestion:

Close [X]

Thank You For Helping Us!

Your message has been sent to W3Schools.

Close [X]
Search w3schools.com:

WEB BUILDING

Download XML Editor FREE Website BUILDER Free HTML5 Templates FREE Website Templates Free HTML Templates

SHARE THIS PAGE

facebook