我有一个包含几行CSS代码的字符串。我想匹配所有发生的:
background:url(" url ");
删除除文件名之外的所有内容。
示例输入:
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");
预期产量
background:url("my_suspicious_file.png"); background:url("my_suspicious_file.jpg"); background:url("my_suspicious_file.gif");
搜索模式:
background:url\(".*\/(.*?)"\);
替换模式:
background:url("$1");
您需要为php转义上面的字符串,我假设您没有使用 s 选项(单线)。
s
更新
一切都在同一条线上:
background:url\("[^"]*\/(.*?)"\);
相同的替换模式。