I'm trying to do a simple regex match but keep running into an IllegalStateException. I've looked at other similar questions with the same issue, and they all say that find() or matches() must first be called before we can use group(). The thing is that I'm already doing that but I'm still getting the exact same exception.
try
{
Pattern p = Pattern.compile(strPattern);
Matcher m = p.matcher(strInput);
m.matches();
m.find();
System.out.println(m.groupCount()); //returns 9 groups
System.out.println(m.group(0)); //will crash here
}
catch (Exception e)
{
e.printStackTrace();
}
Here's the exception I get from this:
java.lang.IllegalStateException: No match found
at java.util.regex.Matcher.group(Unknown Source)
at RegexThing.<init>(RegexThing.java:24)
at Test.main(Test.java:14)