I have been trying and searching for answers, but I can't figured it out. I'm trying to replace a link in a (a href="link") with a redirect link (a href="otherlink.com/redirect.cfm?link=link). The link can be http or https. What I have so far is:
<cfsavecontent variable="s">
This is some text. It is true that <a href="https://www.cnn.com">Harry Potter</a> is a good This is some text. It is true that <a href="http://www.test1.com">Harry Potter</a> is a good This is some text. It is true that <a href="http://www.test2.com">Harry Potter</a> is a good.
<img src="https://test2.com/assets/img/logos/logo.png">
</cfsavecontent>
Then I try to find a link and replace it
<cfset replacedText = s.ReplaceAll(
"(https?://([-\w\.]+)+(:\d+)?(/([\w/_\.]*(\?\S+)?)?)?)",
"redirect.cfm?link=URLEncodedFormat($1)"
) />
There are a least two things not working: 1. Images (img src) are also included, and I don't want that. 2. I want the original link encoded with URLEncodedFormat, and that is not working so far.
Maybe there is much simpler solution for want I'm trying to accomplish. Can someone help me a bit?
Thanks!