Hi All,

I have using VBA in Microsoft Access to replace special characters in a text string. Can you provide assistance in changing the pattern so line feeds are ignored?

Pattern: Need to replace all the characters, not in the pattern (enclosed by []) but I don't want to remove the line breaks.

I don't have much experience with regular expressions but any assistance would be appreciated.

HTML Code:
Sub TestReg()

    Dim strPattern As String
    Dim strReplace As String:
    Dim regEx As Variant
    Dim GCID As String
    strPattern = "[^a-zA-Z0-9 ,/\|().-]" 'The regex pattern to find special characters
    strReplace = ""
    Set regEx = CreateObject("vbscript.regexp")
    ' ^: Any other than in the []
    ' []: All charactors in brackets
    GCID = "Text a ┬ãN-/A %  x" & vbNewLine & "ABC ã"
    ' Configure the regex object
    With regEx
        .Global = True
        .MultiLine = True
        .IgnoreCase = False
        .Pattern = strPattern
    End With

    ' Perform the regex replacement
    GCID = regEx.Replace(GCID, strReplace)

    Debug.Print GCID

' Result: Text a N-/A   xABC 

End Sub