I'm trying to use regex to find a pattern across a string list:
static List<Integer> getMatchingIndexes(List<String> list, String regex) {
ListIterator<String> li = list.listIterator();
List<Integer> indexes = new ArrayList<Integer>();
System.out.println(list.matches("\\w.*"));
while(li.hasNext()) {
int i = li.nextIndex();
String next = li.next();
if(Pattern.matches(regex, next)) {
indexes.add(i);
}
}
System.out.println(indexes);
return indexes;
}
It looks like nothing is showing up int he list, when I try to see if there are any matches (list.matches("\w.*")); (just an example, not the actual regex), it keeps giving me an error:
The method matches(String) is undefined for the type List
How can I use regex on this list?