Globalプロパティ

正規表現ですべての一致を検索するか、最初の一致のみを検索するかを指定するブール値(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."という結果文字列が取得されます。