看看是否满足你的需求,() 表示不同的分组,group0 表示全匹配结果,group1表示第一个括号匹配出来的内容,gruop2、group3 同理
public static void main(String[] args) { String htmlStr = "<Button ALIGN=LEFT ICON=\"NORMAL\" action=\"bypass -h Quest ArenaManager CPrecovery\">CP Recovery: 1,000 Adena</Button>"; String regEx_html = "(<.*?>)(.*?)(<.*?>)"; //定义HTML标签的正则表达式 Pattern p = Pattern.compile(regEx_html, Pattern.CASE_INSENSITIVE); Matcher m = p.matcher(htmlStr); while (m.find()){ System.out.println(m.group(0)); System.out.println(m.group(1)); System.out.println(m.group(2)); System.out.println(m.group(3)); } }
输出结果如下: <Button ALIGN=LEFT ICON="NORMAL" action="bypass -h Quest ArenaManager CPrecovery">CP Recovery: 1,000 Adena</Button> <Button ALIGN=LEFT ICON="NORMAL" action="bypass -h Quest ArenaManager CPrecovery"> CP Recovery: 1,000 Adena </Button>