Test Method

Checks whether a given string matches the regular expression pattern. Test method returns a Boolean value (True or False). It returns True if the string matches the pattern and False if it doesn't.

Syntax: RegExpObject.Test(string)

Arguments: - string: The string that you want to test against the regular expression pattern.

Example:


Dim regEx, str, result

' Create a new RegExp object
Set regEx = CreateObject("VBScript.RegExp")

' Set the pattern for matching email addresses
regEx.IgnoreCase = True
regEx.Global = True
regEx.Pattern = "^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$"

' Test if the string is a valid email
str = "example@example.com"
result = regEx.Test(str)
If result Then
    'Logic for Valid email
Else
    'Logic for Invalid email
End If