How do I use a regular expression to extract a value with specific unit and sum up.
Input at A1, output at A2
I only want to add the value with mm

I tried this code provided from stackoverflow, and I add "?mm" after the (\d+(?:\.\d+)?)but there is an error message.
Function sumNums(str As String) As Double
Dim n As Long
Static rgx As Object, cmat As Object
If rgx Is Nothing Then
    Set rgx = CreateObject("VBScript.RegExp")
End If
With rgx
    .Global = True
    .MultiLine = True
    .Pattern = "(\d+(?:\.\d+)?)?mm"
    If .test(str) Then
        Set cmat = .Execute(str)
        For n = 0 To cmat.Count - 1
            sumNums = sumNums + CDbl(cmat.Item(n))
        Next n
    End If
End With
End Function
 
     
    