Returns a Boolean value indicating the state of the global flag (g) used with a regular expression.
rgExp.global |
Arguments
- rgExp
-
Required. An instance of a Regular Expression object.
Remarks
The global property is read-only, and returns true if the global flag is set for a regular expression, and returns false if it is not. The default value is false.
The global flag, when used, indicates that a search should find all occurrences of the pattern within the searched string, not just the first one. This is also known as global matching.
Example
The following example illustrates the use of the global property.
В | Copy Code |
---|---|
function RegExpPropDemo(re : RegExp) { print("Regular expression: " + re); print("global: " + re.global); print("ignoreCase: " + re.ignoreCase); print("multiline: " + re.multiline); print(); }; // Some regular expression to test the function. var re1 : RegExp = new RegExp("the","i"); // Use the constructor. var re2 = /\w+/gm; // Use a literal. RegExpPropDemo(re1); RegExpPropDemo(re2); RegExpPropDemo(/^\s*$/im); |
The output of this program is:
В | Copy Code |
---|---|
Regular expression: /the/i global: false ignoreCase: true multiline: false Regular expression: /\w+/gm global: true ignoreCase: false multiline: true Regular expression: /^\s*$/im global: false ignoreCase: true multiline: true |