12
I’m trying to understand the difference in the use of these two methods of the class Matcher, but I couldn’t understand it from the description of the documentation that says:
public Boolean Matches()
Attempts to match the entire Region Against the Pattern.public Boolean 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.
What is the difference of use between these two methods? If possible, I would like to see the difference exemplified.
Why did the last find() return false?
– user28595
Because it only had twice the "http://" pattern in String. So the first two times find() finds the pattern, the third time it no longer finds.
– mari
It means that find() looks for the first occurrence it finds from regex inside the string and when it finds, to and returns true, and next time, it ignores occurrences it has already found?
– user28595
In practice, that’s it. find() starts at the beginning of the string the first time it is called, and every subsequent call starts at the first character after the last pattern found (if you found any).
– mari