Hi
Considering that you want to replace text like "ASA1234yy" with a link like "http://www.code.com/ASA1234yy/ABCD", please do the following ,
Set RegX = CreateObject("VBScript.RegExp")
sBody ="gshaai sdijfASA1234yy dds"
msgbox isObject(RegX)
With RegX
.Pattern = "ASA\d{4}\w{2}"
.Global = True
.IgnoreCase = Not MatchCase
End With
RegExpReplace = RegX.Replace(sBody, "http://www.code.com/ASA1234yy/ABCD")
msgbox RegExpReplace
Your code was Ok only thing I changed is the regex pattern.
Now, in case you want to replace each captured value inside your http url, the you need to get all matches using the pattern first then you have to update the url,helper code is here,
Set RegX = CreateObject("VBScript.RegExp")
sBody = "This is ASA4567sa a sampleASA3333df text to show ASA5555sastring replacement in betASA9999ttween"
msgbox isObject(RegX)
With RegX
.Pattern = "ASA\d{4}\w{2}"
.Global = True
.IgnoreCase = Not MatchCase
End With
Set matches = RegX.Execute(sBody)
msgbox matches.Count
If matches.Count > 0 Then
For Each match In matches
RegExpReplace = RegX.Replace(sBody, "http://www.code.com/"+match.value+"/ABCD")
Next
Else
msgbox "No match", 0, "ADT"
End If
msgbox RegExpReplace
Above code:
Input string : "This is ASA4567sa a sampleASA3333df text to show ASA5555sastring replacement in betASA9999ttween"
Output String : "This is http://www.code.com/ASA9999tt/ABCD a samplehttp://www.code.com/ASA9999tt/ABCD text to show http://www.code.com/ASA9999tt/ABCDstring replacement in bethttp://www.code.com/ASA9999tt/ABCDween"
[Replaced 4 matches]
Let me know if that helps.