regEx replace
"Claus Busch" wrote:
the pattern is handled as ONE word. So you get only 1 *.
Calculate the length of the substring to replace first:
Sub ReplaceGlobal()
Dim str As String
Dim ptrn As String, re As Object
Dim lLen As Long
str = "Call me at (982)555-1234"
ptrn = "\(\d{3}\)\d{3}-\d{4}"
lLen = Len(str) - InStr(str, "(") - 1
Set re = New RegExp
re.Pattern = ptrn
re.IgnoreCase = False
re.Global = True
MsgBox re.Replace(str, Application.Rept("*", lLen))
End Sub
Excellent! Thanks again for your help Claus!
|