Java Regular rules

Source: Internet
Author: User
Tags character classes

Common regular Rules:

Structure The
Character
\\ Backslash character
\ r Carriage return character (' \u000d ')
\ n New lines (line break) (' \u000a ')
Character class
[ABC] a,b or c
[^ABC] Any character except a,b , or C (negation)
[A-za-z]
a to z or a to z, the letters at both ends are included (range)
[A-d[m-p]] a to D or m to p:[a-dm-p](set)
[A-z&&[def]] d,e or F(intersection)
[A-Z&&[^BC]] a to Z, except for b and C:[ad-z](minus)
[A-z&&[^m-p]] a to z, not m to p:[a-lq-z](minus)
Predefined character classes
. Any character (may or may not match the line terminator)
\d Numbers:[0-9]
\d Non-numeric: [^0-9]
\s whitespace characters:[\t\n\x0b\f\r]
\s Non-whitespace characters:[^\s]
\w

any word character that includes an underscore :[a-za-z0-9_]

\w Non-word characters:[^\w]
Boundary Matching Device
^ The beginning of the line
$ End of Line
\b Word boundaries
\b Non-word boundary
\a Start of input
\g End of last match
\z The end of the input, only for the last terminator (if any)
\z End of input
Greedy number of words
X? X, not once or once
X* X, 0 or more times
X+ X, one or more times
X{n} X, exactly n times
X{n,} X, at least n times
X{n,m} X, at least n times, but not more than m times
Reluctant number of words
X ?? X, not once or once
X *? X, 0 or more times
X +? X, one or more times
X {n}? X, exactly n times
X {n,}? X, at least n times
X {n,m}? X, at least n times, but not more than m Times
possessive number of words
X ?+ X, not once or once
X *+ X, 0 or more times
X ++ X, one or more times
X {n}+ X, exactly n times
X {n,}+ X, at least n times
X {n,m}+ X, at least n times, but not more than m Times
Logical operator
XY X followed by Y
X | Y X or Y
(X) X, as capturing group
Back reference
\ N Any matching n-th capturing group
References
\ Nothing, but references the following characters
\q Nothing, but all characters are quoted until \e
\e Nothing, but the end of the reference starting from \q

Java Regular rules

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.