myRegExp.global in ECMAScript 262
The global flag for the regular expression.
This property is read-only.
- Property Type
- Boolean
Corresponds to the "g" flag when creating a regular expression, and indicates whether or not the regular expression is global or not when matched against a string. See the exec()
method for implications of this property.
var val;
var oneCat = /cat/; //matches a single occurrence of "cat", case-sensitive
val = oneCat.ignoreCase; // ** false
val = oneCat.global; // ** false
val = oneCat.multiline; // ** false
var anyCat = /cat/i; //matches a single occurence of "cat", case-insensitive
val = anyCat.ignoreCase; // ** true
val = anyCat.global; // ** false
val = anyCat.multiline; // ** false
var all_cats = /cat/g; //matches every occurence of "cat", case-sensitive
val = all_cats.ignoreCase; // ** false
val = all_cats.global; // ** true
val = all_cats.multiline; // ** false
var allCats = /cat/gi; //matches every occurence of "cat", case-insensitive
val = allCats.ignoreCase; // ** true
val = allCats.global; // ** true
val = allCats.multiline; // ** false
var everyLine = /^.+/gm; //matches from the start of a new line to end of that line
val = everyLine.ignoreCase; // ** false
val = everyLine.global; // ** true
val = everyLine.multiline; // ** true