java-Regular Expressions

Source: Internet
Author: User

1. What is a regular expression

An ordered string that defines a set of lookup patterns

2. What are the basic syntax of regular expressions

Single match single character

. Any character

\d Number [0-9]

\d non-digital [^0-9]

\s white space character [\t\n\x0b\f\r]

\w a character [a-za-z_0-9]

Range matches a single character

[ABC] Simple class

[^ABC] Negation

[A-za-z] Range

[A-d[m-p]] [A-dm-p] Union

[A-z&&[def]] [Def] Intersection

[A-Z&&[^BC]] [Ad-z] Subtraction

[A-z&&[^m-p]] [A-lq-z] Subtration

---| match multiple characters greedy mode

? 0 or 1 x

* Any number of the same characters (0 or more) "". Matches ("m*")

+ 1 or more characters

X{n} =n

X{n,} >=n

X{N,M} <=n <=m

--| Boundary Matching

^ABC start with "abc" [^ABC] not "a", "B", "C"

abc$ End With "ABC"

3. How to use regular expressions in Java

Pattern class Matcher Class

The pattern P = pattern.compile () method//First generates a Pattern object for the regular expression

Matcher m = P.matcher () method//Create a Mathcher object from the found content by using the Pattern object Matcher method

M.matches () method

M.find () method//order matching

M.group () method//through find, you can get the group

M.reset () method

M.start () method

M.end () method

4. High-order usage of regular expression

Grouping parentheses number opening parenthesis

Greedy mode. *

Non-greedy mode. *?

java-Regular Expressions

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.