Reference Post address: http://www.oseye.net/user/kevin/blog/170
1, Matcher (): Returns true only if the entire string exactly matches, otherwise false is returned. But if a partial match succeeds, the matching position is moved to the next matching position
2, Lookingat (): Always start from the first character match, no matter whether the match is successful or not, will not continue to match down
3, find (): Partial match, if the match succeeds, returns true, the matching position is moved to the next matching position.
Package Com.qunar.fresh.junweiyu.test;import Java.util.regex.matcher;import Java.util.regex.pattern;public class test_regx {public static void main (string[] args) {Pattern pattern = Pattern.compile ("\\d{3,5}"); String s = "123-34345-234-00"; Matcher Matcher = Pattern.matcher (s); /*matches: The entire match only returns true if the entire character sequence exactly matches successfully, otherwise false is returned. But if the first part matches successfully, the next matching position will be moved */SYSTEM.OUT.PRINTLN (matcher.matches ()); /*false*//* Test Match location */Matcher.find (); System.out.println (Matcher.start ()); /*4*//* Resets the matching position */matcher.reset (); /*find: Partial match, starting at the current position to match, finding a matching substring, moving the next matching position */System.out.println (Matcher.find ());/*true*/System.out.println ( Matcher.group () + "---" + matcher.start ()),/*123---0*/System.out.println (matcher.find ());/*true*/System.ou T.println (Matcher.group () + "---" + matcher.start ())/*34345---4*//*lookingat: Partial match, always match from first character, match succeeded no longer match, match failed, Nor does it continue to match. */System.out.println (Matcher.lookIngat ());/*true*/System.out.println (Matcher.group () + "---" + matcher.start ());/*123---0*/System.out.print ln (Matcher.lookingat ());/*true*/System.out.println (Matcher.group () + "---" + matcher.start ());/*123-0*/}}
The difference between matches (), LookAt (), and find () in the Matcher class in Java