Java Regular Expression

Source: Internet
Author: User
Tags number sign

Regular expression grouping

Precautions

Capturing groups and non-capturing groups

( group numbering with left parenthesis in order )

(exp)

Match exp, and capture text into an automatically named group

Group name starts at 1 and increments (0 is the entire regular expression)

(? <name>exp)

Match exp, and capture the text to a group named name, or you can write (? ') Name ' exp ')

The reverse reference method is: \name, \1

(?: EXP)

Matches exp, does not capture matching text, and does not assign group numbers to this group

Greedy sub-expression

(? >exp)

Non-capturing group, but greedy match is performed on exp

0 width Positive lookahead assertion

(? =exp)

The assertion itself appears after the position can match the expression exp

The group must be a string of the maximum length determination

That cannot appear \s*, \d+, etc.

0 width is recalling post assertion

(? <=exp)

The assertion itself appears before the position can match an expression exp

0 width Negative Predictive antecedent assertion

(?! Exp

Asserts that this position cannot be followed by an expression exp

0 width Negative Review post assertion

(? <!exp)

Assert that the front of this position cannot match an expression exp

Comments

(? #comment)

Regular expression pattern

Note

Unix_lines

(? d)

When matching ^ and $ in multiline mode, only \ n is set to recognize line terminator

Line Terminator 1

Case_insensitive

(? i)

Ignore case when matching characters

By default, only us ASCII characters are considered

COMMENTS

(? x)

Annotation mode

1. Non-escaped whitespace in the regular expression pattern is ignored

2. The number sign (#) is interpreted as the beginning of the comment, not the literal character. All text in the regular expression pattern, from the # character to the end of the line, is interpreted as a comment.

The whitespace of the word characters is interpreted verbatim, regardless of the use of the comments option. For example, the regular expression pattern [.,;:] matches any single empty characters, period, comma, semicolon, or colon.

MULTILINE

(? m)

^ and $ only match the beginning and end of the line, not the beginning and end of the entire input

LITERAL

No

Character mode (metacharacters and escape characters in the input are invalidated)

Dotall (single line)

(? s)

When using this flag, '. ' Symbol matches all characters, including line Terminator

Unicode_case

(? u)

When combined with case_insensitive, use Unicode letter case to match

Canon_eq

No

Consider the equivalence of Unicode character specifications

Java Regular Expression

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.