我想在一个String里凡是有  src="url(images/1.jpg)" 的images前加上这个images的相对路径,怎么实现呢?这个String里有多处 src="url(images/*.jpg)",怎么在每个images前面都加上相对路径呢?麻烦大虾给出具体实现过程,或者思路,谢谢了。

解决方案 »

  1.   

    ultraedit批量的替换就可以了,如果用程序实现就用str.replaceAll('image/','path/image/')
      

  2.   

    using regular expressions, you can do it easily
      

  3.   

    String str = "url(images/1.jpg)xxx url(images/2.jpg) images/";
    str=str.replaceAll("(?<=url\\()(images/)(?=.*?\\.jpg\\))", "path/");
      

  4.   

    String str = "url(images/1.jpg)xxx url(images/2.jpg) images/";
    str = str.replaceAll("(?<=url\\()(images/)(?=.*?\\.jpg\\))", "path/$1");