Skip to content

Instantly share code, notes, and snippets.

@sawilde
Last active April 1, 2019 22:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sawilde/dd4c5d0a4ee7f2e25f3f4e77c1af60c7 to your computer and use it in GitHub Desktop.
Save sawilde/dd4c5d0a4ee7f2e25f3f4e77c1af60c7 to your computer and use it in GitHub Desktop.
RegEx in excel
'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