求高手!正则表达式~~
<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);
测过可以 --------------------编程问答--------------------
6楼的哥们“<”不是元字符,不用反斜杠,不管是用贪婪型还是占位型均可,楼主自己选择。。。 --------------------编程问答--------------------
大哥,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, ""));
}
--------------------编程问答-------------------- +1请结贴 --------------------编程问答--------------------
String text = "<a href=\"http://weibo.com/\" rel=\"nofollow\">新浪微博</a>";
text = text.replaceAll("<[^>]+>", "");
System.out.println(text);
菜鸟飘过 这个我试了可以成功 --------------------编程问答-------------------- 除
补充:Java , Java SE