Pattern\matcher Combination of Java Basics

Source: Internet
Author: User

Written in front: a lot of basic useless forget almost, record, slowly pick up! Multi-Inductive summary ...

Pattern:

Pattern
   
     
    
Extends Object
Implements Serializable

The compiled representation of the regular expression.

A regular expression that is specified as a string must first be compiled into an instance of this class. The resulting pattern can then be used to create an Matcher object that, according to the regular expression, can match any sequence of characters . All the states involved in performing a match reside in the match, so multiple matches can share the same pattern.

Therefore, the typical invocation order is

Pattern p = pattern. compile ("A*b"); Matcher m = p. matcher ("Aaaaab"); Boolean b = M. matches ();

This class is a convenient way to define a method when you use only one regular expression matches . This method compiles an expression and matches the input sequence in a single call. Statement

Boolean B = pattern.matches ("A*b", "Aaaaab");
is equivalent to the three statements above, although it is inefficient for duplicate matches because it does not allow the reuse of compiled schemas.

Matcher:

Matcher
   
     
    
Extends Object
Implements Matchresult

By explaining Pattern the engine that performs the matching operation on the character sequence.

Creates a match from a pattern by invoking the mode's matcher method. After you create a match, you can use it to perform three different matching operations:

    • matchesMethod attempts to match the entire input sequence to the pattern.

    • lookingAtAttempts to match the input sequence to the pattern from the beginning.

    • findmethod to scan the input sequence to find the next subsequence that matches the pattern.

Each method returns a Boolean value that represents success or failure. You can get more information about a successful match by querying the status of the match.

Typical uses are:



Welcome everybody to discuss the study together!

Useful Self-collection!

Record and share, let you and I grow together! Welcome to my other blogs, my blog address: Http://blog.csdn.net/caicongyang




Pattern\matcher Combination of Java Basics

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.