I have a string with several lines of CSS code. I want to match all occurences of :
background:url(" url ");
and remove everything except the filename.
Example input:
background:url("http://external_link.com/images/my_suspicious_file.png");
background:url("rubish.com/images/my_suspicious_file.jpg");
background:url("retarded_input/folder/flodder/my_suspicious_file.gif");
Expected output
background:url("my_suspicious_file.png");
background:url("my_suspicious_file.jpg");
background:url("my_suspicious_file.gif");
Search pattern:
background:url\(".*\/(.*?)"\);
Replace pattern:
background:url("$1");
You'll need to escape the strings above for PHP, and I'm assuming you are not using the s
option (single line).
Update
With everything on the same line:
background:url\("[^"]*\/(.*?)"\);
Same replace pattern.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.