Поделиться через


Execute Method

Executes a regular expression search against a specified string.

object.Execute(string) 

Arguments

  • object
    Required. Always the name of a RegExp object.

  • string
    Required. The text string upon which the regular expression is executed.

Remarks

The actual pattern for the regular expression search is set using the Pattern property of the RegExp object.

The Execute method returns a Matches Collection that contains a Match Object for each match found in string. Execute returns an empty Matches Collection if no match is found.

The following code illustrates the use of the Execute method.

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"))

Requirements

Version 5

Applies To: Regular Expression (RegExp) Object

See Also

Concepts

Regular Expression Programming (Scripting)

Reference

Replace Method (VBScript)

Test Method (VBScript)

Change History

Date

History

Reason

March 2009

Reformatted code in example.

Information enhancement.