<a href="http://weibo.com/" rel="nofollow">新浪微博</a>我想扥到‘新浪微博’,其他的去掉,用string.replaceAll方法不知道怎么写正则,求高手解救~

解决方案 »

  1.   

    string.replaceAll("\\<a[^>]*\\>(.*?)</a>","$1");菜鸟路过
      

  2.   

    str.replaceAll("\\<[^>]*\\>","");
      

  3.   


    String text = "<a href='http://weibo.com/' rel='nofollow'>新浪微博</a>";
    text = text.replaceAll("^<.*?>(.+?)</a>", "$1");
    System.out.println(text);
      

  4.   

    String s="<a href=\"http://weibo.com/\" rel=\"nofollow\">新浪微博</a>".replaceAll("\\<a[^>]*\\>(.*?)</a>","$1");
    System.out.println(s);测过可以
      

  5.   

    大哥,String是不可变类型,你应该把string引用重新赋值
      

  6.   


    public static void main(String[] args) {
    String src = "新浪微博";
    String str = "<a href=\"http://weibo.com/\" rel=\"nofollow\">新浪微博</a>";
    int start = str.indexOf(src);
    int ent = start + src.length();
    System.out.println(str.substring(start, ent));

    String regex = "[a-z\".:\\/<>= ]";
    System.out.println(str.replaceAll(regex, ""));
    }
      

  7.   

    String text = "<a href=\"http://weibo.com/\" rel=\"nofollow\">新浪微博</a>";
    text = text.replaceAll("<[^>]+>", "");
    System.out.println(text);