1)通过\1来引用第一个组中的

public static void main(String[] args) {
String content="<tr>hello world!</tr>";
String regextStr="<(\\w+)>.*?</\\1>";
Pattern pattern=Pattern.compile(regextStr, Pattern.CASE_INSENSITIVE);
Matcher matcher =pattern.matcher(content);
if(matcher.find()){
System.out.println(matcher.group());
}else{
System.out.println("no found");
}
 
}

2)通过$1等来引用

str = str.replaceAll("<!--#include virtual=\"/photosetssi/(\\d+).html(?:\\?\\w+)*\"-->", "<p>@@IMGGROUP=\"" + channelid + "|$1\"@@</p>");