I need to find all src and href’s in a string and replace them with a fully quilifies url.
ex:
src=”/test/style.css?somethinghere” becomes src=”http://www.mydomain.com/test/style.css?somethinghere”
and the same goes for href’s.
I will use them in a web relay server.
I will use regex replace, but what does the regex look like?
You are missing important information, like: what type of regular expression you are interested in. I am assuming that you are referring to perl-compatible regular expression.
In any case this will help in the guidance and theory and answer, and if you let me know the engine/language used I can probably help adapt this to your needs.
I use something similar to collect, pre-process, filter and forward relevant news feeds from various places. MSDN has this problem of relative URIs, here is my configuration for this:
Here you can see the two regular expressions that I am using.
This one restores the content between img and src words and then makes the URLs absolute.
Similarly for anchor tags…
These have been working for quite some time now, over 3 years without issues 🙂
Hope this helps.