0

I have following code :

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));

    }

}

But it's not working, with following exception :

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)

The problem is that the very same regex is working and matching the whole string on sublime text 2, while that on this script I would get IllegalStateException even if I replace dmlMatcher.group(1) by dmlMatcher.group(0).

What's wrong with my program ?

mounaim
  • 1,132
  • 7
  • 29
  • 56

0 Answers0