Last active
April 1, 2019 22:30
-
-
Save sawilde/dd4c5d0a4ee7f2e25f3f4e77c1af60c7 to your computer and use it in GitHub Desktop.
RegEx in excel
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'Turn on developer bar | |
'Add Extension "Microsoft vbscript regex 5.5" | |
' - Select "Developer" tab (I don't have this tab what do I do?) | |
' - Select "Visual Basic" icon from 'Code' ribbon section | |
' - In "Microsoft Visual Basic for Applications" window select "Tools" from the top menu. | |
' - Select "References" | |
' - Check the box next to "Microsoft VBScript Regular Expressions 5.5" to include in your workbook. | |
' - Click "OK" | |
Public Function RegexExtract(ByVal text As String, ByVal expr As String) | |
Dim regEx As New RegExp | |
Dim capture As String | |
With regEx | |
.Global = False | |
.MultiLine = False | |
.IgnoreCase = False | |
.Pattern = expr | |
If .Test(text) Then | |
capture = .Execute(text)(0) | |
RegexExtract = .Replace(capture, "$1") | |
Else | |
RegexExtract = "" | |
End If | |
End With | |
End Function |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment