我使用以下javascript正则表达式来定位我的css中的图片网址并将其包装在液体标记中(用于Shopify主题):
text.replace(/url\(()(.+?)\1\)/g, "url({{'$2' | asset_url}})");
这会改变这个:
url(example.jpg)
到此:
url({{'example.jpg' | asset_url}})
这很好用,但我的css还包含我不想定位的数据网址。 e.g。
url("data:image/svg+xml;charset=US-ASCII,%3C%3Fxml%20version%3D%221.0%22%20encoding%3D%22utf-8%22%3F%3E%3C!DOCTYPE%20svg%20PUBLIC%20%22-%2F%2FW3C%2F%2FDTD%20SVG%201.1%2F%2FEN%22%20%22http%3A%2F%2Fwww.w3.org%2FGraphics%2FSVG%2F1.1%2FDTD%2Fsvg11.dtd%22%3E%3Csvg%20version%3D%221.1%22%20id%3D%22Layer_1%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20xmlns%3Axlink%3D%22http%3A%2F%2Fwww.w3.org%2F1999%2Fxlink%22%20x%3D%220px%22%20y%3D%220px%22%20%20width%3D%2212px%22%20height%3D%2216px%22%20viewBox%3D%220%200%2012%2016%22%20enable-background%3D%22new%200%200%2012%2016%22%20xml%3Aspace%3D%22preserve%22%3E%3Cg%3E%20%3Cg%3E%20%20%3Cg%3E%20%20%20%3Cg%3E%20%20%20%20%3Cpolygon%20fill%3D%22%2300ABA8%22%20points%3D%229.8%2C15.3%2011.1%2C13.7%204.1%2C8%2011.1%2C2.3%209.8%2C0.7%200.9%2C8%20%20%20%20%20%22%2F%3E%20%20%20%3C%2Fg%3E%20%20%3C%2Fg%3E%20%3C%2Fg%3E%3C%2Fg%3E%3C%2Fsvg%3E")
我如何修改我的正则表达式以排除上面示例中的数据网址?
答案 0 :(得分:0)
尝试使用此常规exp
/url\(.*?(gif|png|jpg|jpeg)\'\)/ig