当前位置:编程学习 > JAVA >>

求高手!正则表达式~~

<a href="http://weibo.com/" rel="nofollow">新浪微博</a>

我想扥到‘新浪微博’,其他的去掉,用string.replaceAll方法不知道怎么写正则,求高手解救~ --------------------编程问答-------------------- 高手啊 ~ 没人来解么 --------------------编程问答-------------------- 高手啊 ~ 没人来解么 --------------------编程问答-------------------- string.replaceAll("\\<a[^>]*\\>(.*?)</a>","$1");菜鸟路过 --------------------编程问答-------------------- 不行啊 ,上面 我测试了 刚刚 --------------------编程问答-------------------- str.replaceAll("\\<[^>]*\\>",""); --------------------编程问答-------------------- --------------------编程问答--------------------

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


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



测过可以 --------------------编程问答--------------------
引用 5 楼  的回复:
str.replaceAll("\\<[^>]*\\>","");

6楼的哥们“<”不是元字符,不用反斜杠,不管是用贪婪型还是占位型均可,楼主自己选择。。。 --------------------编程问答--------------------
引用 4 楼  的回复:
不行啊 ,上面 我测试了 刚刚

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

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, ""));
}

--------------------编程问答--------------------

String text = "<a href=\"http://weibo.com/\" rel=\"nofollow\">新浪微博</a>";
text = text.replaceAll("<[^>]+>", "");
System.out.println(text);
--------------------编程问答--------------------
引用 12 楼 cscript 的回复:
Java code?123String text = "<a href=\"http://weibo.com/\" rel=\"nofollow\">新浪微博</a>";text = text.replaceAll("<[^>]+>", "");System.out.println(text);
+1请结贴 --------------------编程问答--------------------
引用 12 楼 cscript 的回复:
Java code?123String text = "<a href=\"http://weibo.com/\" rel=\"nofollow\">新浪微博</a>";text = text.replaceAll("<[^>]+>", "");System.out.println(text);

菜鸟飘过 这个我试了可以成功 --------------------编程问答-------------------- 除
补充:Java ,  Java SE
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,