Export (0) Print
Expand All

Test Method (VBScript)

Updated: March 2009

Executes a regular expression search against a specified string and returns a Boolean value that indicates if a pattern match was found.

object.Test(string) 

Object

Required. Always the name of a RegExp object.

String

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

The actual pattern for the regular expression search is set using the Pattern property of the RegExp object. The RegExp.Global property has no effect on the Test method.

The Test method returns True if a pattern match is found; False if no match is found.

The following code illustrates the use of the Test method.

Function RegExpTest(patrn, strng)
  Dim regEx, retVal

  ' Create regular expression.
  Set regEx = New RegExp
  regEx.Pattern = patrn
  regEx.IgnoreCase = False

  ' Do the search test.
  retVal = regEx.Test(strng)

  If retVal Then
    RegExpTest = "One or more matches were found."
  Else
    RegExpTest = "No match was found."
  End If
End Function
MsgBox(RegExpTest("is.", "IS1 is2 IS3 is4"))

Date

History

Reason

March 2009

Reformatted example.

Information enhancement.

Community Additions

Show:
© 2014 Microsoft