RegEx to extract URL from CSS background styling

前端 未结 5 1703
Happy的楠姐
Happy的楠姐 2021-02-03 11:03

I have a string in this form:

url(\"http://www.example.com/imgs/backgrounds/bg80.jpg\") repeat scroll 10% 0% transparent

This is from a CSS sty

5条回答
  •  一整个雨季
    2021-02-03 11:43

    Just capture anything between ( and )

    var url = str.match(/\((.*?)\)/)[1].replace(/('|")/g,'');
    
    var image = new Image();
    image.src = url;
    

    FIDDLE

提交回复
热议问题