The approach I wanted to use was to replace all occurrences until unless if given string (to be replaced) is inside an absolute url. 
Sample case for ```match != from``` (replace '/static/'):
"http://www.mysite.org/static/bar.jpeg"

@dmitchell yes you are right about third group (p3). As args p1, p2, p3, offset, string will not be used so should I replace ```function replacer(match, p1, p2, offset, string){``` with ```function replacer(match){```?
I have added sample urls in my comment below.