Método Test

Verifica se determinada string corresponde ao padrão de expressão regular. O método Test retorna um valor Booliano (True ou False). Ele retornará True se a string corresponder ao padrão; caso contrário, retornará False.

Sintaxe: RegExpObject.Test(string)

Argumentos: - string: A string a ser testada em relação ao padrão de expressão regular.

Exemplo:

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