Regular Expressions _ Overview

Source: Internet
Author: User
Tags character set
Standard Character Set

Large/lowercase, uppercase instead of meaning
\d: any number 0-9
\w: any alphanumeric underline
\s: spaces, tabs, line breaks
.: matches any symbol other than a newline character, to match all uses of [\s\s]
escape character: \ Custom Character Set

[2-8]: Any number in the 2~8

1. Special symbols are included in brackets to lose special meaning except ^,-
2. Standard character set, in addition to the decimal point, if included in brackets, the custom character set will contain the collection
quantifier

Number of modifier matches
{n}: repeat n times
{m,n}: repeat at least m, repeat n times
{m,}: repeat at least m times
. : Match expression 0 or 1 times (0~1 times)
+: at least 1 times
*: 0 or any number of times


1. Only the previous expression is applied, and the preceding multiple expressions can be expanded together to represent a whole
2. Default greedy mode, the more times the better
3. Non-greedy mode, after the quantifier is added.
character Bounds

Match a position that is not a character but a position that matches a certain condition
^ Where the string begins to match (example: ^a)
Match where the string ends (example: B matches where the string ends (example: b)
b matches a word boundary, the preceding character and the following character are not all \w match patterns

Ignore case mode:
Ignore case

Single-line mode:
The entire text is treated as a string, with only one start and end. Use. (decimal point) can match any character including line breaks

Multi-line mode
Make each row a string with the beginning and end of each line
If you also want to get the beginning and end elements of a string, you can use \a\z (example: a\a b\z) selectors and groupings

|: or
(): the expression in parentheses can be decorated as a whole when the capturing group is decorated with the number of matches. When matching results are taken, the expressions in parentheses match to the content that can be obtained separately
(?: Exception): non-capturing group, does not save () the content of the neutron expression match, after the match fails the reverse reference (\num)

Each pair () is assigned a number, and the capture using () is automatically numbered from 1 based on the order of the opening brackets, referencing the grouped captured string. (count by opening parenthesis, starting with number 1)
Such as:

(a\d?b) \1

Is the result of a 0/1 number between two AB stitching together: abab,a1ba1b pre-search (0 wide assertion)

Match a position

(? =exp): The assertion itself appears after the position can match exp
(? <=exp): Asserts that it appears before the position can match exp
(?! EXP): The assertion itself appears after the position does not match exp
(? >!exp): Asserts that it appears before the position can match exp

The results that satisfy the EXP expression do not count toward the total result.
Cases:
AB (? =ab)
There is ab behind AB, i.e. Abab

Example:
Fixed phone: 0\d{2,3}-\d (7,9)
Phone Number: 1[35789]\d{9}
e-mail: [\w-]+@[a-z0-9a-z]+ (. [ A-za-z]) {.}

Format of fixed phone:
The correct format for dialing to China abroad is: 0086+ Local area code + phone number
In the domestic dial the correct format is: Local area code + telephone number
3-bit Area code 8-digit number or 4-bit Area code 7-digit number

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.