Global 屬性
設置或返回一個 Boolean 值,該值指明在整個搜索字符串時模式是全部匹配還是只匹配第一個。
object.Global [= True | False ]
對象 參數(shù)總是 RegExp 對象。如果搜索應用于整個字符串,Global 屬性的值為 True,否則其值為 False。默認的設置為 False。
說明
下面的代碼說明了 Global 屬性的用法(改變賦予 Global 屬性的值并觀察其效果):
Function RegExpTest(patrn, strng) Dim regEx ,match,matches '
建立變量。 Set regEx = New RegExp '
建立規(guī)范表達式。 regEx.Pattern = patrn '
設置模式。 regEx.IgnoreCase = True '
設置是否區(qū)分字母的大小寫。 regEx.Global = True '
設置全程性質。set matches= regEx.Execute(strng) '
執(zhí)行搜索。for each match in matches '
重復匹配集合RetStr=RetStr "Match found at position "
RetStr=RetStrMatch.FirstIndex".Match Value is '"
RetStr=RetStrMatch.Value"'."vbCRLF Next
RegExpTest=RetStr
End Function
MsgBox(RegExpTest("is.", "IS1 is2 IS3 is4"))