Requireend and Hitend in Java regularization

Source: Internet
Author: User

  

 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.