Regular Expression Program
- by david robers
Hi I have the following text:
SMWABCCA
ABCCAEZZRHM
NABCCAYJG
XABCCA
ABCCADK
ABCCASKIYRH
ABCCAKY
PQABCCAK
ABCCAKQ
This method takes a regex in out by the user and SHOULD print out the Strings it applies to but seems to print out something completely different:
private void matchIt(String regex) {
Pattern p = Pattern.compile(regex);
Matcher m = null;
boolean found = false;
for(int i = 0; i < data.length; i++){
m = p.matcher(data[i]);
if(m.find()){
out.println(data[i]);
found = true;
}
}
if(!found){
out.println("Pattern Not Found");
}
}
When inputting "[C]"
It outputs:
SMWABCCA
ABCCAEZZRHM
NABCCAYJG
XABCCA
ABCCADK
ABCCASKIYRH
ABCCAKY
PQABCCAK
ABCCAKQ
Any ideas why? I think I'm using m.find() improperly...