JavaScript RegExp g modifier
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





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 »
JavaScript RegExp Object