我在java代码中获得的了页面传入的一个字符串,有如下格式:
<img src="http://localhost:8070/info/images/ico/execl.gif" width="16" height="16" />
<img src="http://192.168.3.23:8070/info/images/ico/execl.gif" width="16" height="16" />
<a href="http://localhost:8070/info/test.do>
<a href="http://192.168.3.23:8070/info/test.do>
请问有哪位知道使用java正则表达式将该字符串中链接由绝对地址转换为相对地址
<img src="./images/ico/execl.gif" width="16" height="16" />
<img src="./images/ico/execl.gif" width="16" height="16" />
<a href="./test.do>
<a href="./test.do>
谢谢!

解决方案 »

  1.   

    line.replaceAll("http://[^/]*/[^/]*", ".");
      

  2.   

    public class A{
      public static void main(String[] args){
        String a = "http://aabbcc/a.txt";
        String b = a.replaceAll(".*\\/","./");
        System.out.println(a);
        System.out.println(b);
      }
    }
      

  3.   

    public class A{
      public static void main(String[] args){
        String a = "http://aabbcc/a.txt";
        String b = a.replaceAll("http:\\/\\/.*\\/","./");
        System.out.println(a);
        System.out.println(b);
      }
    }