Forum Discussion
rodsan724
Oct 14, 2021Brass Contributor
Help creating a custom function in Power Query that has regex capability
Can someone please help me create a custom function in Power Query that can do regular expression like the ones in this post (Best Response).
Basically, I want to be able to extract some information from a log file that appears in a field in my database query and put in a new custom column in Excel
Here are the regexes from linked post above:
Function getTargetCountV2(ByVal content As String, ByVal pattern As String) As String
Dim Matches As Object
With CreateObject("VBScript.RegExp")
.Global = True
.ignorecase = True
.pattern = pattern
If .test(content) Then
Set Matches = .Execute(content)
getTargetCountV2 = Matches.Count
Else
getTargetCountV2 = ""
End If
End With
End Function
Function getTargetValueV2(ByVal content As String, pattern As String) As String
Dim Matches As Object
With CreateObject("VBScript.RegExp")
.Global = True
.ignorecase = True
.pattern = pattern
If .test(content) Then
Set Matches = .Execute(content)
getTargetValueV2 = Matches(Matches.Count - 1).submatches(0)
End If
End With
End Function
No RepliesBe the first to reply