Global Property (VBScript)

Updated: March 2009

Sets or returns a Boolean value that indicates if a pattern should match all occurrences in an entire search string or just the first one.


                      object.Global [= True | False ]

The object argument is always a RegExp object. The value of the Global property is True if the search applies to the entire string, False if it does not. Default is False.

The following code illustrates the use of the Global property (change the value assigned to Global property to see its effect):

Function RegExpTest(patrn, strng)
    Dim regEx, Match, Matches, s

    ' Create the regular expression.
    Set regEx = New RegExp
    regEx.Pattern = patrn
    regEx.IgnoreCase = True
    regEx.Global = True

    ' Do the search.
    Set Matches = regEx.Execute(strng)

    ' Iterate through the Matches collection.
    s = ""
    For Each Match in Matches
      s = s & "Match found at position "
      s = s & Match.FirstIndex & ". "
      s = s & "Match Value is '"
      s = s & Match.Value & "'."
      s = s & vbCRLF
    Next

    RegExpTest = s
End Function
MsgBox(RegExpTest("is.", "IS1 is2 IS3 is4"))

Date

History

Reason

March 2009

Reformatted code example.

Information enhancement.

Community Additions

Show:
© 2014 Microsoft