I’m looking for an Excel function that I can put in a cell to do a regex search of the contents of another cell. Is there anything available to do this? I’d prefer not to have to add VB Script to the spreadsheet for this because I can hard-code a solution faster. It’s just that the fastest solution would be a function. I can’t find one, though. So maybe there’s nothing.
Anyone know?
Answer
You can simply add a reference to ‘Microsoft VBScript Regular Expressions 5.5’ in the VBE to expose the VBScript.dll regex functions to Excel. Writing a simple regex function is then trivial, e.g.
Public Function emailCheck(rawEmail As String) As Boolean
Dim reg As New RegExp
reg.Pattern = "^[\w-\.]{1,}\@([\da-zA-Z-]{1,}\.){1,}[\da-zA-Z-]{2,4}$"
emailCheck = False
If reg.Test(rawEmail) Then
emailCheck = True
End If
End Function
Attribution
Source : Link , Question Author : Erick Robertson , Answer Author : KyleMit