i want java regex all matching index : <p>The person who is studying kmp algorithm.
I am wondering if the kmp algorithm is too difficult to replace with regex.
I do not like this result.
The results I want are 0 and 1.
And I wonder if the regex time complexity is O (n + m).</p>

<pre><code>public static void main(String[] args) throws IOException {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    String t = "aaa";   
    Pattern p = Pattern.compile("aa");
    Matcher m = p.matcher(t);
    ArrayList&lt;Integer&gt; ans = new ArrayList&lt;Integer&gt;();

    while (m.find()) ans.add(m.start());
    for (int i : ans)
        System.out.print(i + " ");
}
</code></pre>

<p>i want Result [0 1]
this Result [1]</p>
