Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

RegExp g modifier

JavaScript RegExp g modifier

RegExp Object Reference JavaScript RegExp Object


Definition and Usage

The g modifier performs a global match (finds all matches rather than stopping after the first match).

Syntax

new RegExp("

regexp

","g")

Or a simpler way:

/

regexp

/g


Browser support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support the g modifier


Example

Example 1

Perform a global search for "is":

var str="Is this all there is?";

var patt1=/is/g;

The text marked below shows where the expression found matches:

Is th

is

all there

is

?

Try it »

Example 2

Perform a global, case-insensitive search for "is":

var str="Is this all there is?";

var patt1=/is/gi;

The text marked below shows where the expression found matches:

Is

th

is

all there

is

?

Try it »


RegExp Object Reference JavaScript RegExp Object