-1

I have not been able to find in Stackoverflow advice on finding specific URLs and appending them. I am looking to create "deep links" using a popular affiliate network within HTML content. For example here is some HTML:

<h2>This is a title</h2>
<p>this is some text</p>
<p><a href="https://www.macys.com">link to macys</a></p>
<p><a href="https://www.google.com">link to google</a></p>
<p>something else</p>

</body>
</html>

I want to use Regex to find just the Macys link (not the Google link) in the HTML and append the URLs with the "deep link" code from the affiliate network. So it looks like this:

<html>
<body>

<h2>This is a title</h2>
<p>this is some text</p>
<p><a href="https://click.linksynergy.com/deeplink?id=idnumber&mid=3184&u1=123&murl=http://www.macys.com">link to macys</a></p>
<p><a href="https://www.google.com">link to google</a></p>
<p>something else</p>

</body>
</html>
  • 1
    The posted question does not appear to include [any attempt](https://idownvotedbecau.se/noattempt/) at all to solve the problem. StackOverflow expects you to [try to solve your own problem first](https://meta.stackoverflow.com/questions/261592/how-much-research-effort-is-expected-of-stack-overflow-users), as your attempts help us to better understand what you want. Please edit the question to show what you've tried, so as to illustrate a specific roadblock you're running into a [MCVE]. For more information, please see [ask] and take the [tour]. – CertainPerformance Dec 28 '18 at 23:45
  • I have tried this regex (?:http|https):\/\/((?:[\w-]+)(?:\.[\w-]+)+)(?:[\w.,@?^=%&:\/~+#-]*[\w@?^=%&\/~+#-])? which is [poted here](https://regex101.com/r/vT2lF3/1) but it does not show how to find just a specific URL rather than all urls. – Tim Mueller Dec 28 '18 at 23:49
  • [Obligatory link to useful post about parsing (X)HTML with Regex](https://stackoverflow.com/a/1732454/62576) – Ken White Dec 28 '18 at 23:50
  • Why do you think you need a regex for this? A text editor's find/replace functionality will work fine. Find *http://www.macy.com* and replace it with your new content. – Ken White Dec 28 '18 at 23:59
  • I am using a no code development framework called Bubble (bubble.is) and creating a blogging tool for affiliate marketing. when a user creates a post i want to save it and modify the urls in the post to "deep links" I think I am getting close with this regex (?:http|https):\/\/((?:[\w-]+)(?:\.macys+)+)(?:[\w.,@?^=%&:\/~+#-]*[\w@?^=%&\/~+#-])? but it only finds URLs that have "www" in front of Macys. I am worried that if someone posts "http:// no www macys.com" it will not catch it. – Tim Mueller Dec 29 '18 at 00:13
  • @KenWhite you're right. I just did a find and replace without regex. Thanks for the advice. – Tim Mueller Dec 29 '18 at 01:37

1 Answers1

-1

I did a find and replace for http://macys.com, and www.macys.com, and http://www.macys.com and it works.