import java.util.regex.Matcher;
import java.util.regex.Pattern;// 来 自 时 代 J a v a 公 众 号 - nowjava.com
public class Main {
public static void main(String[] args) throws Exception {
// Compile regular expression with a back reference to group 1
String patternStr = "<(\\S+?).*?>(.*?)</\\1>";
Pattern pattern = Pattern.compile(patternStr);
Matcher matcher = pattern.matcher("");
// Set the input
matcher.reset("test this is test xx <tag a=b> yy test test</tag> zz");
// Get tagname and contents of tag// from 时 代 Java - nowjava.com
boolean matchFound = matcher.find();
System.out.println(matchFound);
String tagname = matcher.group(1);
System.out.println(tagname);
/**代码未完, 请加载全部代码(NowJava.com).**/
本文系作者在时代Java发表,未经许可,不得转载。如有侵权,请联系nowjava@qq.com删除。