I have this function that I have used for a while that removes tabs and other unwanted things from my strings. However I recently wanted to adapt it for using windows paths, so I want to change it so it leaves the : and \ characters in strings. I believe all I need to add the character "\" to the .Pattern line. However I've tried the code below and it doesn't work for some reason, can anyone help?
many thanks
Public Function PrepareString(TextLine As String) As String
Dim oRegex As Object
If oRegex Is Nothing Then oRegex = CreateObject("vbscript.regexp")
With oRegex
.Global = True
'Allow A-Z, a-z, 0-9, -, /, :, _ and '
.Pattern = "[^A-Za-z0-9 -/\:_']"
TextLine = .Replace(TextLine, vbNullString)
End With
TextLine = Trim(TextLine)
PrepareString = TextLine
End Function