Regular Expression summary, Regular Expression

Source: Internet
Author: User

Regular Expression summary, Regular Expression

. Any single character except \ n

[] Character filtering, filtering one in the middle. If ^ is added, no characters in it will appear.

| Meaning or location (the priority is very low. a | bcd matches a or bcd and does not match acd)

() Change the operation Priority and extract the group

* Qualifier, indicating that the previous expression appears 0 or multiple times

+ Qualifier, indicating that the expression of the front edge must appear once or multiple times, at least once

? A qualifier, indicating that the expression on the front must appear 0 or once at most once. The greedy mode is terminated.

{N} qualifier, which specifies that the previous expression must appear n times

The {n,} qualifier. The expression that limits the front edge must appear at least n times.

The {n, m} qualifier. The expression that limits the front edge must appear at least n times and at most m times.

^ Indicates the start of a string [not in]

$ Indicates the end of a string.

\ D indicates [0-9]

\ D indicates [^ 0-9]

\ S indicates all the blank spaces and invisible characters (line breaks, tabs, etc)

\ S indicates all characters except \ s

\ W indicates [0-9a-za-z _] underline indicates Chinese Characters

\ W indicates all characters except \ w

\ B indicates the word boundary (assertion, only judgment, not matching)

 

 

Represents any single character:

[\ S \ S]

[\ W \ W]

[\ D \ D]

 

^ A | B $: Indicates starting with a or ending with B (because | has a low priority)

 

Determine whether a string is an ID card number:

1. A string of 15 or 18 characters. The first character cannot be 0.

2. If it is 15 digits, all are numbers.

3. If it is 18 bits, the first 17 are all numbers, and the end may be numbers or X (both in case)

Method 1: ^ [1-9] ([0-9] {13} | [0-9] {16}) [0-9Xx] $

Method 2: ^ [1-9] [0-9] {14} ([0-9] {2} [0-9Xx])? $

 

Determine whether the string is a correct domestic phone number, regardless of the extension:

1. area code: 3 or 4 digits

2. Phone: 7 or 8

3. The "-" between the area code and the phone number can be absent or appear once.

4. Or all the five-digit numbers are valid.

5. All 11 mobile phone numbers are also valid

Method: ^ (\ d {3, 4 }-? \ D {7, 8}) | (\ d {5}) $

Note: because the first 11-digit phone number is included, you do not need to fill in any more

May 22, 2015

By: champly

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.