Code example for Matcher

Methods: group, groupCount, matches

0
        Pattern fpr = Pattern
                .compile(
                        ".*?([a-fA-F0-9: ]*[a-fA-F0-9]{4} {0,3}:?[a-fA-F0-9]{4} {0,3}:?[a-fA-F0-9]{4} {0,3}:?[a-fA-F0-9]{4} {0,3}:?).*", 
                        Pattern.MULTILINE | Pattern.DOTALL);
        Matcher matcher = fpr.matcher(text);
        if (matcher.matches()) {
            Log.i(TAG, "matches: " + matcher.groupCount());
            // group(0) is entire match, group(1) is first match of parens 
            String match = matcher.group(1);
            Log.i(TAG, "found: " + match);
            match = match.replaceAll("[ :]", "");
            if (match.length() > 40)
                match = match.substring(match.length() - 40);
            return match;
        } 
        return null; 
    } 
 
    /* this works for standard apps, like Gmail. but not apps like K-9 */ 
    private String getContentName(ContentResolver resolver, Uri uri) {
        // Gmail and K-9's attachment providers give the filename in this column