I am having issues figuring out how to split on multiple delimiters using regular expressions in access vba. I want to take a string say “This;is,really:annoying” and a tring user-defined delimiters separated by pipes (;|,) so that I would obtain the following result “This” , “is”, “really:annoying” No matter what I do I cannot get this to work. In python I would just use re.split but vba has no such option that I know of. I have posted the code that I have tried:
Private Sub Splitter(ByVal UnmodText As String, ByVal SplitDelimiters As String)
Dim SplitExp As New RegExp
Dim SplitMatches As MatchCollection
Dim SplitMatch As Match
SplitExp.IgnoreCase = True
SplitExp.Global = True
'SplitExp.Pattern = ".(" & SplitDelimiters & ")" & "|(?<=" & SplitDelimiters & ").$"
'SplitExp.Pattern = ".{0,}(?=(" & SplitDelimiters & "))"
SplitExp.Pattern = "(?!(" & SplitDelimiters & "){2})"
MsgBox SplitExp.Pattern
Set SplitMatches = SplitExp.Execute(UnmodText)
For Each SplitMatch In SplitMatches
MsgBox SplitMatch.Value
Next
End Sub
Any help would be greatly appreciated!
This will return a variant array given a string to split, and a string containing pipe-delimited separators.