在Rubular我是在试探我的正则表达式:Java的正则表达式不工作(但确实在Rubular)
(\d+).html
测试字符串:
"/magnoliaAuthor/Services/services/07.html"
正如我需要,我回到 “07”作为第一个比赛组。完善。 我需要这个表达式在Java环境,所以我写了这段代码:
import java.util.regex.*;
class Main
{
public static void main (String[] args)
{
String jcrPath = "/magnoliaAuthor/Services/services/07.html";
Pattern pattern = Pattern.compile("(\\d+).html");
Matcher matcher = pattern.matcher(jcrPath);
System.out.println(matcher.group());
}
}
至于解释here,我加了问题再\我的正则表达式。 可悲的是我,编译和运行代码时,我得到以下异常: java.lang.IllegalStateException:没有找到匹配
有谁知道为什么没有任何比赛吗?
点也是一个特殊字符。尝试'“(\\ d +)\\。html”'。另外,你在整个字符串上匹配正则表达式,所以它应该是'“。*(\\ d +)\\。html”',其中'。+'开头是任意字符序列。 – Jacopofar 2013-05-14 13:15:59