我有以下代码:
public class RegexTest {
public static void main(String[] args) {
String s="insert into dossier (CODE_SERVICE ,NUM_DOSSIER , INDICE )values ('224','25437','24')";
String dmlRegex = ".*((update|insert|delete).*)";
Pattern dmlPattern = Pattern.compile(dmlRegex);
Matcher dmlMatcher = dmlPattern.matcher(s);
System.out.println("Opération : "+dmlMatcher.group(1));
}
}
但它不起作用,但有以下例外:
Exception in thread "main" java.lang.IllegalStateException: No match found
at java.util.regex.Matcher.group(Matcher.java:485)
at ma.ancfcc.dossierMatalabRapport.RegexTest.main(RegexTest.java:15)
问题在于,正则表达式正在工作并且匹配sublime text 2上的整个字符串,而在此脚本上,即使我将IllegalStateException
替换为dmlMatcher.group(1)
,我也会得到dmlMatcher.group(0)
}。
我的计划有什么问题?