求解java正则表达式

kinson_hu123 2010-11-23 08:51:54
现在有个字符串:"<test1>abc<test2>efg<test3>"
我想通过正则表达式得到< >里面的内容如 test1 test2 test3
请高手解答谢谢
...全文
63 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
kinson_hu123 2010-11-23
  • 打赏
  • 举报
回复
谢谢大家 解决问题了 十分谢谢 呵呵
kinson_hu123 2010-11-23
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 hbgzg3006 的回复:]
String regex = "<(.*?)>";
....
while(xxx.find())
System.out.print(xxx.group(1));
[/Quote]
嘿嘿 谢谢了 解决了
YY_loveyong 2010-11-23
  • 打赏
  • 举报
回复
路过打酱油...
xuyisen_1987 2010-11-23
  • 打赏
  • 举报
回复

package com.xuyisen.monitor.test;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Test {

public static void main(String[] args) {
String s = "<test1>abc<test2>efg<test3>";
String regex = "<(.+?)>";
Pattern p = Pattern.compile(regex);
Matcher m = p.matcher(s);
while(m.find()){
System.out.println(m.group(1));
}
}
}

xuyisen_1987 2010-11-23
  • 打赏
  • 举报
回复


package com.xuyisen.monitor.test;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Test {

public static void main(String[] args) {
String s = "<test1>abc<test2>efg<test3>";
String regex = "<(.+?)>";
Pattern p = Pattern.compile(regex);
Matcher m = p.matcher(s);
while(m.find()){
System.out.println(m.group(1));
}
}
}
hbgzg3006 2010-11-23
  • 打赏
  • 举报
回复
String regex = "<(.*?)>";
....
while(xxx.find())
System.out.print(xxx.group(1));

62,612

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧