JavaScript Regular expression popular explanation fast memory

Source: Internet
Author: User

1. The most important three symbols in regular expressions:

1.1 B

In regular expressions, B has 3 types of parentheses:

1.1.1 square brackets "[".

The square brackets "[" are the characters that need to be matched. Bracketed content only matches one single character.

^[ab]$

1.1.2 Curly Brace "{"

The curly brace "{" is the number of matching characters specified.

^[ab]{3}$


1.1.3 Parenthesis "("

The parentheses "(" are used for grouping.)

^ (AB) $

1.2 C

The caret "^" indicates the beginning of the regular type.

^a

^ When used at the beginning of the brackets, the characters in parentheses are excluded.

^[^0-9]$

1.3 $

The dollar sign "$" indicates the end of the regular type.

com$

2. Regular expression validation

Recommend a validation regular expression URL: https://regexper.com/

2.1 Example

^[0-9]{3,7}$

The above regular expression is a number with a minimum length of 3 and a maximum of 7.

The result of the validation is:

2.2 ' │ ' symbol equals or operation

^ (1|2) $

3. Quick command

3.1 \d = number [0-9] Note D preceded by an escape character \

^\d$

Uppercase d:\d denotes non-numeric

^\d$

3.2 Underline any word character \w

^\w$

Capital W: \w denotes non-word

^\w$

3.3 0 times or more occurrences *

^[0-9]*$

3.4 At least once occurred +

^[0-9]+$

3.5 0 or 1 times?

^[0-9]?$

2017.8.25 Update

4. Non-greedy mode

Add a question mark directly behind the quantifier? It's a non-greedy pattern.

/(

JavaScript Regular expression popular explanation fast memory

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.