html - Javascript - Find all occurences of brackets in a string and replace the content depending on it's content -
i want search occurrences of url() in string , replace content on basis of it's content.
so example there are these different url-contents:
url("assets/images/pic.jpg") url('assets/images/pic.jpg') url("../images/pic.jpg") url(../images/pic.jpg) url('../images/pic.jpg') url('http://website.com/images/pic.jpg') and link should inserted in front of url, depending on content:
link = "file://dir/first/" if there ../ in front url, should removed , link should in front of it.
and if there http:// in front, of http-link should removed, except fil @ end , link should inserted in front:
so following link should transformed to:
url('http://website.com/images/pic.jpg') url("file://dir/first/pic.jpg") the problem is, link in between ", ' or nothing.
i know how replace ../-things
response=response.replace(/url\(\'\.\.\//g, "url('"+link); response=response.replace(/url\(\"\.\.\//g, 'url("'+link); response=response.replace(/url\(\.\.\//g, "url("+link); does know solution?
thanks!
you may try if want touch first 2 statements.
string.replace(/(url\(['"]?)(?:\.\.\/|http:\/\/[^)]*\/)?/g, "$1" + link); if don't want touch first 2 remove optional quantifier ? present @ last.
string.replace(/(url\(['"]?)(?:\.\.\/|http:\/\/[^)]*\/)/g, "$1" + link);
Comments
Post a Comment