This is my code to find \"ab\" pattern in given string.
import java.util.regex.*;
public class RegExp
{
public static void main(String[] arg
As you can read in the documentation of find():
Attempts to find the next subsequence of the input sequence that matches the pattern.
This method starts at the beginning of this matcher's region, or, if a previous invocation of the method was successful and the matcher has not since been reset, at the first character not matched by the previous match.
If the match succeeds then more information can be obtained via the start, end, and group methods.
So when you call matcher(String text) the first time nothing happens. It is only when you call find(), that it aims to find the first match. If you call find() a second time, it will aim to find the next match and so on.
The following sequence diagram describes what happens:
The matcher is constructed and each time find() is called the "cursor" is moved to the next match.