I need to get all substrings matching a regex, I know I can probably build an automaton for it, but I am looking for a simpler solution.
the problem is, Matcher.find() doesn't return all results.
String str = "abaca";
Matcher matcher = Pattern.compile("a.a").matcher(str);
while (matcher.find()) {
System.out.println(str.substring(matcher.start(),matcher.end()));
}
The result is aba and not aba,acaas I want...
any ideas?
EDIT:
another example: for string=abaa, regex=a.*a I am expecting to get aba,abaa,aa
p.s. if it cannot be achieved using regular expressions, it's also an answer, I just want to know I'm not re-inventing the wheel for something the language already provides me with...