I'm trying to do a quick sanity check ... and its failure. 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 I would expect to see group 1: a . But instead, I get an IllegalStateException: no match found , and I have no idea why.
Edit: I am also trying to print groupCount() , and it says there is 1.
source share