Need help with parsing line where keywords included in brackets [].
I tried but have wrong result:
public class App {
public static void main(String[] args) {
Matcher mtr = Pattern.compile("(\\w+-\\w+|\\w+)+").matcher("[foo-bar] [baz][qux]");
if (mtr.find()) for (int i = 0; i < mtr.groupCount(); i++) {
System.out.println(mtr.group(i));
}
}
}
Result(wrong):
foo-bar
Me need:
foo-bar
baz
qux
What should be regex that parse string as on last example ?
find()in a loop until it stops finding. the groups are the groups for a single match, not all the matches.