Global Property

Boolean value (True or False) that specifies whether the regular expression should search for all matches or just the first one.

Note:

Default value is False.

Set Property Usage:

Syntax: Object.Global= "<True/False>"

Example: Global Flag Set to False


Dim regEx, inputStr, result
' Create a new RegExp object
Set regEx = CreateObject("VBScript.RegExp")

' Set the pattern to match the word "cat"
regEx.IgnoreCase = True
regEx.Global = False
regEx.Pattern = "cat"

' Input string
inputStr = "The Cat sat on the cat mat."

' Replace "cat" with "dog"
result = regEx.Replace(inputStr, "dog")

'Now result has the value "The dog sat on the cat mat."

In the above example Global property is set to False. So, resulted string will have only first instances of the cat with dog. If you want to search through complete input string you need to set the Global property to True. After setting Global = True, for the above example you will get result string as: "The dog sat on the dog mat."