我正在尝试在字符串中查找数字。我知道查找数字是由 \d 完成的,但是当我在如下示例文本上尝试时:
127.0.0.1 - - [11/Dec/2012:11:57:36 -0500] "GET http:// localhost/ HTTP/1.1" 503 418 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.95 Safari/537.11"
使用我的 java 代码
Pattern test = Pattern.compile("\\d");
testLine = in.readLine(); // basically the text above
// extract date and time log in and number of times a user has hit the page
numTimesAccess++; // increment number of lines in a count
System.out.println(test.matcher(testLine).group());
System.out.println(test.matcher(testLine).start());
System.out.println(test.matcher(testLine).end());
我收到一个错误异常,指出未找到匹配项。我的正则表达式模式或我试图访问与模式匹配的文本的方式有问题。