Code example for Matcher

Methods: groupCount

0
        ); 
 
        Matcher m = p.matcher("1 (919) 555-1212");
 
        assertEquals("groupCount is incorrect, see http://b/issue?id=759412",
                3, m.groupCount());
    } 
 
    public void testGroups() throws Exception { 
        Pattern p = Pattern.compile("(b)([c|d])(z*)");
        Matcher m = p.matcher("abcdefg");
 
        /* Must call find() first, otherwise group*() are undefined. */ 
        assertTrue(m.find());
 
        assertEquals(3, m.groupCount());
 
        assertEquals("bc", m.group(0));
        assertEquals("b", m.group(1));
        assertEquals("c", m.group(2));
        assertEquals("", m.group(3));