Kauboven Address: http://www.oseye.net/user/kevin/blog/170
1, Matcher (): Returns true only if the entire string is completely matched, otherwise false.
But suppose a partial match succeeds. The matching position is moved to the next matching position
2, Lookingat (): Always start with the first character to match. No match succeeds, no further matching down
3. Find (): Partial match, assuming the match is successful. Returns true, where 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 the entire sequence of characters succeeds, returns True, otherwise false.But assuming the previous 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: partially matched. Matches are always made from the first character, and the match succeeds and no longer continues. The match failed, and the match was not continued.
*/System.out.println (Matcher.lookingat ());/*true*/System.out.println (Matcher.group () + "---" + matcher.sta RT ());/*123---0*/System.out.println (Matcher.lookingat ());/*true*/System.out.println (Matcher.group () + "--- "+ Matcher.start ());/*123-0*/}}
Java is the difference between matches (), LookAt (), and find () in Matcher classes