regEx replace
Hi Robert,
Am Fri, 3 Apr 2015 01:27:59 -0700 schrieb Robert Crandal:
That one didn't work. The output was
"Call me at *"
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
Regards
Claus B.
--
Vista Ultimate / Windows7
Office 2007 Ultimate / 2010 Professional
|