Packagetest;ImportJava.util.regex.Matcher;ImportJava.util.regex.Pattern; Public classmain{//Hitend (), the result is true, enter more data at the end, whether to change the match result 1.true to False 2.false to true 3. Match text changes//returns false, the matching result has been determined, including for this determination//requireend (), only if the match succeeds, is true, indicates that more input data may cause failure, false input more, may change the matching text, but not fail Public Static voidMain (string[] args) {string[] matcherstrs= { "1234", "1234.>.567", ">", ">.567", ">=", ">=.567", "oops" }; Pattern Pattern= Pattern.compile ("\\d+\\b|[ ><]=? "); Matcher m=NULL; for(String matcherstr:matcherstrs) {m=Pattern.matcher (MATCHERSTR); BooleanFind_result =true; if(Find_result =M.find ()) {System.out.println (String.Format ("Regular is%s, match text is%s, match succeeded:%s, match result is%s", M.pattern (), Matcherstr, Find_result, Find_result? M.group (): "Match failed")); System.out.println ("Hitend () is" +m.hitend ()); System.out.println ("Requireend () is" +m.requireend ()); } } }}
Results Analysis:
The regular is \d+\b|. [><]=?, match text is 1234, Match succeeded: true, match result is 1234
Hitend () is true//if the end adds 5, the text changes, plus a, the match fails, so Hitend is true
Requireend () is true//plus a, resulting in a failure
The regular is \d+\b|. [><]=?, match text is 1234.>.567, match succeeded: true, match result is 1234
Hitend () is false//1234 has been determined, and the end has nothing to do with false
Requireend () is false//does not cause failure
The regular is \d+\b|. [><]=?, match text is;, Match succeeded: true, match result is >
Hitend () is true//plus =, matching text changes
Requireend () is false//plus = text changes, but does not fail, so false
The regular is \d+\b|. [><]=?, match text is >.567, match succeeded: true, match result is >
Hitend () is false//> not at the end and has been determined successfully
Requireend () is false//determined success
The regular is \d+\b|. [><]=?, match text is >=, match succeeded: true, match result is >=
Hitend () is false//? It's 0-1, it doesn't change the result.
Requireend () is false//will not fail
The regular is \d+\b|. [><]=?, match text is >=.567, match succeeded: true, match result is >=
Hitend () is false//not at the end
Requireend () is false//not at the end
First see if the match results are at the end
Requireend and Hitend in Java regularization