Java Regular expression (regular)

Source: Internet
Author: User

Oh, mom, it hurts----regular expression

The regular is used to handle complex text types.

Standard Character Set:

\d---> stands for 0-9 any number \d----> any character except the number \w-----> Letter (case) number, underline full match \w-----> all characters except alphanumeric underscore

\s-----> spaces, line breaks, tabs

\s-----> All characters except the Space wrap tab

. -----> match any character except line break

Custom Character Set (* *)

Use the [] match method, match the characters within [],  use ^ in [] to  indicate the inverse  -to indicate from which to which interval
[[email protected]]-----> match the characters of Q or P or 3 or @

[A-f]------> match characters between a-f

[^a-v0-7]----> matches characters in addition to A-v 0-7

Use of quantifiers: special symbols for modifying the number of matches

{n}----> expression repeats n times
\D{6}: Match 6 digits
{\d\d} {6}: Match 12 digits
{M,n}----> expression repeats at least m times, the maximum repetition n times is greedy mode, if there are N times will continue to append n times

{m,n}? -----> Repeat M-times, non-greedy mode

{m,}-------> at least m times, m+ is counted

? ---------> Match Expression 0 or one time equals {0,1}
A/d?b: Match AB a5b
+----------> At least one time equals {1}
A/d+b: Matching a2b a34b

* ----------> is equivalent to {0}


Character bounds: is the position, not the character

^------> Character Start place
^o: string starting with O
$------> where the string ends
o$: string ending with O
\b------> Not all is/w's expression.
qw\b: Only this QW 123QW is configured

Mobile phone number Matching

1[358]\B{9}  starts with------1, and the 2nd bit can be 3.5.8 Other 9 digits

Mailbox match

[\w\-] [Email protected] [A-za-z0-9]+ (\.[ a-za-z]{2,5}) {}

Common regular matches

Java uses the regular:

Create a regular expression and matcher two objects using the Pattern under the Java.util package

Pattern p= pattern.compile ("\\d"); To create a regular expression

MATCHR m =p.matcher ("ddeff34");//need to match the regular

while (M.find ()) {

M.group ();//Remove

}

Java Regular expression (regular)

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.