1. In an Excel workbook, press Alt+F11 to open VBA/Macros window.
2. Add reference to regex under Tools > References and selecting Microsoft VBScript Regular Expression 5.5
3. Then add module by Insert > Module
4. Paste the following code in the editor window that appears and close the VBA/Macros window.
Rem Source: https://www.oreilly.com/library/view/vbscript-in-a/1565927206/re155.html
Rem Source: Point 7 on https://stackoverflow.com/a/43128681
Function Regex(text As Range, ByVal pattern As String, Optional ByVal replaceWith As String, _
Optional ignore_case As Boolean = True, Optional global_search As Boolean = False, _
Optional multi_line As Boolean = False)
Dim re As RegExp
Set re = New RegExp
With re
.IgnoreCase = ignore_case 'ignoring cases while regex engine performs the search.
.pattern = pattern 'declaring regex pattern.
.Global = global_search 'restricting regex to find only first match.
.MultiLine = multi_line
If .test(text.Value) Then 'Testing if the pattern matches or not
If (Len(replaceWith) = 0) Then
Regex = .Execute(text.Value)(0)
Else
Regex = .Replace(text.Value, replaceWith)
End If
Else
Regex = ""
End If
End With
End Function