0

I am not good in regex, need help in the below scenario. I have a big HTML response as a string having different anchor tags with URLs. I am planning to find that URL's from string and replace that with encrypted URLs.

Now the problem is that how I can pick that URL one by one, encrypt that and again set that in HTML string. My html looks like as:

<body>
.........
<a href="http://site1.com/text/123"> site1 </a>
.........
<a href="http://site1.com/text/345"> site2 </a>
.........
</body>
sForSujit
  • 987
  • 1
  • 10
  • 24
Umais Gillani
  • 608
  • 4
  • 9
  • SO is not a code writing service (asking for a regex is just the same as asking for code). Give it a try yourself and ask a specific question that includes your code if you are stuck! – ParkerHalo Aug 01 '17 at 10:04
  • 2
    It's better to parse HTML with XML parser, not with the regex. – ikleschenkov Aug 01 '17 at 10:06
  • You might try something yourself first. A few questions to guide you: how would you describe a pattern for urls (can be something like "first there is http or https, then there's a colon, ...")? What should happen to urls that are not in an anchor tag? What type of html will you apply this to? Do you have control over the contents? Is there a possibility that things could like urls that are not? Might a real HTML/XML parser be better suited for your problem? – Thomas Aug 01 '17 at 10:06
  • @ikleschenkov thanks for the suggestion, its a good idea to parse as XML, This idea didn't came in my mind, Thanks. – Umais Gillani Aug 01 '17 at 10:08

0 Answers0