I'm working with Cisco router data. In a router dump, there will be lines that say "interface <some interface_name>".
I load an array with this:
arrLocalTemp = FilterRegEx(arrRouterDataNew, "^interface Vlan*")
FWIW, 'FilterRegEx' is a function I wrote that does what it's name says (I'll include it below, for critique and improvement).
The array I get will contain every line in my router data pull that starts with "interface Vlan*". But, I don't want every element to start with "interface ".
Here is my one-line cleanup (is this the best way?):
arrLocalTemp = Split(Replace(Join(arrLocalTemp, vbCrLf), "interface ", vbNullString), vbCrLf)
The reason I'm asking is this the most efficient way to do this?
As promised, here is my FilterRegEx function:
Function FilterRegEx(arrInput As Variant, Ptn$) As Variant
Dim regexOne As Object
Dim inputLine As Variant, Match As Variant, theMatches As Variant
Dim strToMatch$, strMatches$, arrMatches$()
Set regexOne = New VBScript_RegExp_55.RegExp
'
With regexOne
.pattern = Ptn
.Global = True
For Each inputLine In arrInput
strToMatch = inputLine
Set theMatches = .Execute(strToMatch)
For Each Match In theMatches
strMatches = IIf(Len(strMatches), strMatches & vbCrLf & inputLine, inputLine)
Next
Next
End With
arrMatches = Split(strMatches, vbCrLf)
FilterRegEx = arrMatches
strMatches = vbNullString
Erase arrMatches
End Function
Bookmarks