regex – understanding excel regular expressions vba code

hi im trying to learn using regular expressions in excel vba and im wondering if someone could explain what does each line do from the code below:

.Pattern = “([$()^|\[]{}+*?.-])”

ptn = .Replace(r, “$1”)

.Pattern = “\b” & ptn & “\b”

For Each m In .Execute(r(, 4))

r(, 4).Characters(m.firstindex + 1, m.Length).Font.Bold = True

Sub test()
    Dim rng As Range, r As Range, m As Object, ptn As String
    Columns("f").Font.Bold = False
    Set rng = Range("c2", Range("c" & Rows.Count).End(xlUp))
    With CreateObject("VBScript.RegExp")
        .Global = True
        .IgnoreCase = True
        For Each r In rng
            If r <> "" Then
                .Pattern = "([$()^|\\\[\]{}+*?.-])"
                ptn = .Replace(r, "\$1")
                .Pattern = "\b" & ptn & "\b"
                For Each m In .Execute(r(, 4))
                    r(, 4).Characters(m.firstindex + 1, m.Length).Font.Bold = True
                Next
            End If
        Next
    End With
End Sub

Read more here: Source link