What is the Pattern class?

August 13th, 2008 by uCertify Leave a reply »

Pattern is a final class present in the java.util.regex package. It is used to define and hold regular expressions. This class works with the Matcher class to perform the match operations.

The Pattern class defines no public constructors. To create a pattern, a static method compile is used as follows:

static Pattern compile(String pattern): This static method compiles the given regular expression into a pattern.

The other important methods of the Pattern class are as follows:

  • static Pattern compile(String regex, int flags)

    This static method compiles the given regular expression into a pattern with the given flags.

  • public Matcher matcher(CharSequence input)
    This method creates a matcher that will match the given input against this pattern. It takes the character sequence to be matched and returns a matcher for the pattern.
  • static boolean matches(String regex, CharSequence input)
    This static method compiles the given regular expression and attempts to match the given input against it.
  • public String pattern()
    This method returns a String that represents the regular expression from which this pattern was compiled.
Like this article? Share it with others
If you like this article, please leave a comment or subscribe this blog via RSS or via e-mail, Bookmark and share through your network. Click the AddThis button below. Thanks.
  • Share/Bookmark
Advertisement

Leave a Reply

uCertify.com | Our Company | Articles | Contact Us | News and Press Release | uCertify India | Entries (RSS)
MCSE: MCSA, MCTS, MCITP    JAVA Certification: SCJP, SCWCD    Cisco Certification: CCNA, CCENT    A+, Network+, Security+ Project+
Oracle Certification: OCP 11g, OCP 10g, OCA 11g, OCA 10g    CIW foundation    EC-212-32,    CISSP    Photoshop ACE CS4    Adobe Flash ACE, PMP, CAPM
© 2008 uCertify.com. All rights reserved. All trademarks are the property of their respective owners.