例如:
<h1>内容<h1>
正则表达式:
/<.+?>(.+?)<.+?>/
Java实现:
String htmlStr = "<h1>XXX<h1/><h2>YYY<h2/>"; Pattern pattern = Pattern.compile("<.+?>(.+?)<.+?>"); Matcher matcher = pattern.matcher(htmlStr); // 获得结果集 while (matcher.find()) { System.out.println(matcher.group(1)); }