JAVA Regular Expressions

Source: Internet
Author: User

What exactly is a regular expression?

Regular expressions, also known as regular Expressions . (English: Regular Expression, often abbreviated in code as regex, RegExp, or re), a concept of computer science. Regular tables are often used to retrieve and replace text that conforms to a pattern (rule).

When writing a program or Web page that handles strings, there is often a need to find strings that match certain complex rules. Regular expressions are the tools used to describe these rules. In other words, the regular expression is the code that records the text rule.

It is possible that you have used the wildcard character (wildcard) for file lookup under Windows/dos, which is * and?. If you want to find all the Word documents in a directory, you will search for *.doc. Here, * will be interpreted as an arbitrary string. Like wildcard characters, regular expressions are also tools for text matching, but rather than wildcards, it can describe your needs more precisely--and, of course, the cost is more complex--you can write a regular expression that looks for all 0, followed by 2-3 numbers, then a hyphen "-", The last is a 7-or 8-digit string (like 010-12345678 or 0376-7654321).

The regular expression defines the pattern of the string.

Regular expressions can be used to search, edit, or manipulate text.

Regular expressions are not limited to a single language, but have subtle differences in each language.

Java Regular expressions are the most similar to Perl.

The Java.util.regex package mainly consists of the following three classes:

    • Pattern class: ( mode )

      pattern object is a compiled representation of a regular expression. The Pattern class has no public constructor method. To create a pattern object, you must first call its public static compilation method, which returns a Pattern object. The method takes a regular expression as its first argument.

    • Matcher Class: (Match)

      matcher An object is an engine that interprets and matches an input string. Like the pattern class, Matcher does not have a public construction method. You need to invoke the Matcher method of the Pattern object to get a Matcher object.

    • patternsyntaxexcept Ion:

      Patternsyntaxexception is a non-mandatory exception class that represents a syntax error in a regular expression pattern.

Data reference:

Http://www.jb51.net/tools/zhengze.html

JAVA Regular Expressions

Related Article

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.