Use Regex to Match relative image URLs and then use string replace to make them absolute using Javascript <p>I want to use javascript regex to find all relative URLs and then make them absolute using the string replace function in javascript. I tried to following but it didn't work:(Note: i have tried searching this site but couldn't find the perfect solution)</p> <pre><code>data = data.replace(/\/\.(jpg|png|gif|bmp)$\/i/gi, "http://example.com" + "$1"); </code></pre> <p>What I am trying to achieve is replace the relative image URLs with their absolute forms in an external data pulled using YQL and JSON. I also found another script that would do the job, but it would only apply to the on page HTML element, and NOT to the content inside the div containing the externally loaded content. </p> <p>Any method other than the data.replace doesn't seem to work in my case, i tried another script that worked perfectly but only on the on page html, not externally loaded HTML.</p> <p>This is my first post here. Any help would be appreciated. </p>