日期:2014-05-18  浏览次数:20600 次

Java正则表达式
我要从“<td>aaa</td>”中提取“aaa”,下面是我的正则表达式,但这句调试不过去。是不是Java对正则表达式有特殊的语法限制?大家帮我看看呢。

Pattern pattern = Pattern.compile("(?<=\\<td.*\\>)[^\\<\\>]*(?=\\</td\\>)");

------解决方案--------------------
不支持这种方式的*
------解决方案--------------------
Pattern sp = Pattern.compile("(?<=\\<td\\>)[^\\<\\>]*(?=\\</td\\>)");
Matcher matcher = sp.matcher(x);

while (matcher.find()) {
System.out.println(matcher.group());
}

------解决方案--------------------
String str = "<td>aaa</td>";
        Pattern pattern = Pattern.compile("<td>(.*)</td>");
        
        Matcher m = pattern.matcher(str);
        while(m.find())
        {
            System.out.println(m.group(1));
        }