Proprietà Global

Valore booleano (True o False) che specifica se l'espressione regolare deve cercare tutte le corrispondenze o solo la prima.

Note:

Il valore predefinito è False.

Uso della proprietà Set

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

Esempio: impostare il flag Global su 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."

Nell'esempio precedente la proprietà Global è impostata su False. Pertanto, la stringa risultante conterrà solo le prime istanze della parola "cat" con la parola "dog". Se si desidera eseguire una ricerca nella stringa di input completa, è necessario impostare la proprietà Global su True. Dopo aver impostato Global = True, per l'esempio precedente si otterrà la stringa risultante: "The dog sat on the dog mat".