Thread: regEx replace
View Single Post
  #21   Report Post  
Posted to microsoft.public.excel.programming
Robert Crandal[_3_] Robert Crandal[_3_] is offline
external usenet poster
 
Posts: 161
Default 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!