Java Fundamentals Hardening 78: The acquisition of regular expressions (use of Pattern and Matcher classes)

Source: Internet
Author: User

1. Get Features:

Pattern and Matcher classes are used together

2. Use case:

1  Packagecn.itcast_05;2 3 ImportJava.util.regex.Matcher;4 ImportJava.util.regex.Pattern;5 6 /*7 * Get features8 * Use of pattern and Matcher classes9  *        Ten * Basic Use order of the pattern and the matching device One  */ A  Public classRegexdemo { -      Public Static voidMain (string[] args) { -         //Typical invocation order of patterns and matches the         //compiling regular expressions into schema objects -Pattern p = pattern.compile ("A*b"); -         //The matching object is obtained by the pattern object, which is what is needed to match the string -Matcher m = P.matcher ("Aaaaab"); +         //the ability to invoke a match object -         Booleanb =m.matches (); + System.out.println (b); A          at         //This is a judgment function, but if you make a judgment, it's a bit of a hassle, we do it directly using the string method . -String s = "Aaaaab"; -String regex = "A*b"; -         BooleanBB =s.matches (regex); - System.out.println (BB); -     } in}

The results are as follows:

Java Fundamentals Hardening 78: The acquisition of regular expressions (use of Pattern and Matcher classes)

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.