Im trying to do a quick sanity check... and its failing. Here is my code -
import java.util.regex.*;
public class Tester {
public static void main(String[] args) {
String s = "a";
Pattern p = Pattern.compile("^(a)$");
Matcher m = p.matcher(s);
System.out.println("group 1: " +m.group(1));
}
}
And what I would expect is to see group 1: a
. But instead I get an IllegalStateException: no match found
and I have no idea why.
Edit: I also tries printing out groupCount()
and it says there is 1.