用於指定正規表示式應搜尋所有配對項目,或僅搜尋第一個配對項目的布林值 (True 或 False)。
Note:
預設值為 False。
設定特性用法:
語法:Object.Global= "<True/False>"
範例:Global 旗標設為 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."
在上述範例中,Global 特性設為 False。因此,結果字串中只會將第一個出現的 cat 替換為 dog。如果您要搜尋完整的輸入字串,則必須將 Global 特性設為 True。設定 Global = True 之後,上述範例的結果字串將會是:"The dog sat on the dog mat"。