Java Regular Expressions

Posted by david robers on Stack Overflow See other posts from Stack Overflow or by david robers
Published on 2011-01-16T01:08:07Z Indexed on 2011/01/16 1:54 UTC
Read the original article Hit count: 488

Filed under:
|
|

Hi All,

Im struggling to understand the regex documentation.

How would I find the strings that contain exactly one C in the following text:

ABCCAMNL        YOOBABCCA
XNABCCA        ZDXUABCCA
TAQABCC ISABCCA REABCCA
CABCAMONPT

Edit:

private void matchIt(String regex, ArrayList<String> d) {
        Pattern p = Pattern.compile("[\\w^C]");
        Matcher m = p.matcher(regex);
        for (int i = 0; i < d.size(); i++) {
            p.matcher(d.get(i));
            if(m.find()){
                out.println(d.get(i));
            }
        }
    }

i have the above function and it only outputs:

ABCCAMNL YOOBABCCA

Why is that?

© Stack Overflow or respective owner

Related posts about java

Related posts about regex