我尝试使用正则表达式提取值,但是当我尝试打印输出时出现此异常:
Exception in thread "Main Thread" java.lang.IllegalStateException: No match found
at java.util.regex.Matcher.group(Matcher.java:468)
at TEST.main(TEST.java:21)
这是我的代码:
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class TEST {
/**
* @param args
*/
public static void main(String[] args) {
String string = "10/06/2013 01:45";
Pattern pattern = Pattern.compile("([0-9]{1,})/([0-9]{1,})/([0-9]{4}) ([0-9]{1,}):([0-9]{1,})");
Matcher matcher = pattern.matcher(string);
System.out.println(matcher.group(1)+"\n"+matcher.group(2)+"\n"+matcher.group(3)+"\n"+matcher.group(4)+"\n"+matcher.group(5)+"\n");
}
}
为什么这段代码不起作用?