Wednesday, August 13, 2014

Excel Regular Expressions

Sub RegEx_Tester()
    Dim objRegExp_1 As Object
    Dim regExp_Matches As Object
    
    Dim strToSearch As String
    
    Set objRegExp_1 = CreateObject("vbscript.regexp")
    objRegExp_1.Global = True
    objRegExp_1.IgnoreCase = True
    objRegExp_1.Pattern = "[a-z,A-Z]*@[a-z,A-Z]*.com"
    
    strToSearch = "ABC@xyz.com"
    
    Set regExp_Matches = objRegExp_1.Execute(strToSearch)
    
    If regExp_Matches.Count = 1 Then
        MsgBox ("This string is a valid email address.")
    End If
    
End Sub

No comments: