JavaScript RegExp gModifier
JavaScript RegExp Object
Definition and Usage
The g modifier is used to perform a global match (find all matches rather than stopping after the first match is found).
Syntax
new RegExp("regexp","g")
Or a simpler way:
/regexp/g
Or a simpler way:
/regexp/g
Browser Support
![]()
![]()
![]()
![]()
![]()
All major browsers support the g modifier.
Examples
Example 1
Perform a global search for "is":
var str="Is this all there is?";
var patt1=/is/g;
var patt1=/is/g;
The text belowis markedto show the positions where the expression gets matches:
Is this all there is?
Try it Yourself »
Example 2
Perform a global, case-insensitive search for "is":
var str="Is this all there is?";
var patt1=/is/gi;
var patt1=/is/gi;
The text belowis markedto show the positions where the expression gets matches:
Is this all there is?
Try it Yourself »
JavaScript RegExp Object
Other Extensions