Code example for Matcher

Methods: replaceAll

0
    public void testReplaceAll() throws Exception { 
        // Begins with non-matching text, ends with matching text 
        Pattern p = Pattern.compile("a*b");
        Matcher m = p.matcher("fooaabfooaabfooabfoob");
 
        String r = m.replaceAll("-");
        assertEquals("foo-foo-foo-foo-", r);
 
        // Begins with matching text, ends with non-matching text 
        p = Pattern.compile("a*b");
        m = p.matcher("aabfooaabfooabfoobfoo");
 
        r = m.replaceAll("-");
        assertEquals("-foo-foo-foo-foo", r);
    } 
 
    public void testReplaceFirst() throws Exception { 
        // Begins with non-matching text, ends with matching text 
        Pattern p = Pattern.compile("a*b");
        Matcher m = p.matcher("fooaabfooaabfooabfoob");