欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

一个正则表达式的问题.

程序员文章站 2022-06-02 18:12:01
...
		
		String needToMatch = "<table><tr>fadsf</tr><tr>dafqewrdf</tr></table>";

		
		Pattern p = Pattern.compile("\\Q<tr>\\E.*\\Q</tr>\\E");
		Matcher matcher = p.matcher(needToMatch);
		while(matcher.find()){
            System.out.println("I found the text \"" + matcher.group() +
                    "\" starting at index " + matcher.start() +
                    " and ending at index " + matcher.end() + ".");
		}




得到的是
I found the text "<tr>fadsf</tr><tr>dafqewrdf</tr>" starting at index 7 and ending at index 39.

其实我想解析成<tr>fadsf</tr> 和 <tr>dafqewrdf</tr>

请问这个正则表达式该怎么写呢? thanks