I cant to seem to extract strings from an Array List that match my regular expression. The Array-List contains line by line strings read into it by Buffered Reader. I can system print out the strings and see them however when i use regular expressions its not finding them and fails.
My goal is the following:
1-loop through array
2-find match/pattern
3- system print out only the regex match
For example my array contains strings like this on each line iatbbb,AAC lawiat,3DD,4FF,KKL
The reg expression i use is (\s*[a-z]+)|([a-z]+\s*,) which is suppose to select the first set of characters up to the comma like this (iatbbb) and not (iatbbb,). The goal is to write the first set of characters to a file and the comma and 3 characters after that to a another file. However right now I am just trying to do the first part print them out in the eclipse console.
I don't know what I could be doing wrong and I am new to using matches and pattern matches and help would be appreciated.
ArrayList<String> wfnold = new ArrayList<>();// array that holds strings
String clientRegex = "(\\s*[a-z]+)|([a-z]+\\s*)";
Pattern p = Pattern.compile(clientRegex);
for (String s: wfnold) {
if (p.matcher(s).matches()){
System.out.println(s);
}else{
System.out.println("fail");
}
}