Url regular matching for help

the string to be matched looks something like this:

url("http://localhost:8888/img/4ecdd7cd00b149c1ba169c2671dcdc82.png")

the result I want:

http://localhost:8888/img/4ecdd7cd00b149c1ba169c2671dcdc82.png

what I"m trying to write is regular:

let url= "url("http://localhost:8888/img/4ecdd7cd00b149c1ba169c2671dcdc82.png")"
let reg = /[^url("")]+[^\s]*/gi;
            
reg.exec(url)

print result:


your regular string doesn't need to be regular, just intercept the string

str = "url(xxx)"
str.substring(4,str.length-1) // xxx

reg=/url\((.*?)\)/

clipboard.png


var url= 'url("http://localhost:8888/img/4ecdd7cd00b149c1ba169c2671dcdc82.png")'
var reg = /^url\(\"(.*)\"\)/;
console.log(reg.exec(url)[1])

when you encounter a scene and write a regular, and you don't know if it's right or what's wrong, you can go to regex101.com to see what your regular means.


 let url= 'url("http://localhost:8888/img/4ecdd7cd00b149c1ba169c2671dcdc82.png")'
 let reg = /\((.+?)\)/g,
     reg2 = /\"(.+?)\"/g;
            
console.log(reg2.exec(reg.exec(url)[1])[1])

str.replace(/url\("([^"]*)"\)/i,"$1");
Menu