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?

link|improve this question

67% accept rate
feedback

3 Answers

up vote 2 down vote accepted

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
link|improve this answer
feedback

MoreFunc.xll is a free addin that has Regex functionality.

There are some other third-party addins that can do Regex also.

There are no true native worksheet functions to do it, but if you have a specific search to do you can probably use other functions to get the job done.

link|improve this answer
Thanks for the confirmation. I found that library, but we were hoping to have something that didn't require us to distribute a library, too. – Erick Robertson Aug 26 '10 at 15:04
@Erick, yep, I hate adding addins to my spreadsheets, a big pain to keep track of them. Unless you need complete regex flexibility, you can probably get the job done with other functions. There's a lot of tricks in Excel. Post specific requests here. – Lance Roberts Aug 26 '10 at 15:16
feedback

Here is a library of regexes you can use in excel. Its not a dll, but is some vb code

http://ramblings.mcpher.com/Home/excelquirks/regular-expressions

Bruce

link|improve this answer
1  
-1 Flagged as spam. A library of regular expressions do not help, and this is your blog. See: blogger.com/profile/16065806789478255746 – Erick Robertson Dec 7 '11 at 14:22
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.