布尔值(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"。