Difference between matches() and find() in Java Regex

Java 8Object Oriented ProgrammingProgramming

matches() method in the Matcher class checks and match the regular expression of the whole text passed to the Pattern.matcher() method. The matches() method returns true If the regular expression matches the whole text. If not, the matches() method returns false.

Whereas find() search for the occurrence of the regular expression passes to Pattern.matcher(). if multiple matches found in the text then find() will search for the first match, then multiple calls to find() will match others in sequence.    

raja
Published on 03-May-2018 06:52:11
Advertisements