2011-06-06 162 views
0

我有下面的CSS正则表达式来替换路径

div style="background: transparent url('http://test.com/assets/admin/R7AcNoiUzbrr89.png') no-repeat"></div> 

div style="background: transparent url(http://another.com/assets/admin/R7AcNeer89.png) no-repeat"></div> 

如何才能摆脱主机名与一个正则表达式?

感谢

+0

这是来自IDE还是脚本?让我们知道您正在使用的技术。 – 2011-06-06 16:28:18

+0

您使用哪种语言替换值? Python? Java? Php? – 2011-06-06 16:29:30

+0

脚本。 JavaScript或Python。你喜欢的任何东西 – Thomas 2011-06-06 16:29:36

回答

0

您可以尝试更换:

style="(.*)(http://([^/])*)(.*)" 

由:

style="$1$4" 
0

红宝石:

str.gsub(/http:\/\/[^\/]+([^\)])/i, '/') 

JS:

str.replace(/http:\/\/[^\/]+([^\)])/i, '/') 
+0

嗨。理想情况下,它应该包含url(在正则表达式中,因为我不想替换任何其他元素(图像等) – Thomas 2011-06-06 16:45:21