go to previous page   go to home page   go to next page


No. Both matches() and lookingAt() start at the beginning of the string each time you call them.

(It is OK to call them more than once with the same string, but you get no new information.)

find(int start), start(), and end()

To start the search at a specific location within the string, use find(int start). The parameter start is the index of the character where the search begins. It can be any value zero up to the length of the string minus one. Remember that string indexes start at zero.

After find() has succeeded, start() evaluates to the index of the first character in the substring that matched. end() evaluates to the index of the character one after the substring that matched.

If the pattern includes capture groups, then the starting and ending index of a group are returned by start(int groupNumber) and end(int groupNumber). Of course, this only works after matching has succeeded and for legitimate group numbers.


What does ( matcher.end()-matcher.start() ) compute after matcher.find() has succeeded?