---of JavaScript objects RegExp

Source: Internet
Author: User

1. Overview

A regular expression is an object that describes a character pattern.

Regular expressions are used to match string patterns and retrieve replacements;

2. Grammar

The former is a pattern and the latter is a modifier.

var New " XYZ " " I "  ); // equivalent to var reg =/xyz/i;

Note : When creating a regular object using the constructor, you need to precede the meta character with a backslash (\)

var New REGEXP ("\\w+"); // equivalent to var reg =/\w+/;

3. Modifier
I-----------  multi-line matching

4. Square brackets

Square brackets are used to find characters in a range.

[0-9] Find any number from 0 to 9 [a-z] find any character from A to Z [a-z] find any character from A to Z [a-z] find any character from A to Z [ADGK] 
     find any character within a given set [^adgk]   | Blue | Green) Find any of the options you specify

5, Meta-character

Characters that have special meanings

.          Any single character (other than line break) \w         Word character \w         non-word character \d         numeric character \d         non-numeric character \s         white space character \s         non-whitespace character \ n         line break \ r         Enter

6. quantifier
n+                 matches any string containing at least onen *                 matches any string n that contains 0 or more n?                 Match any string containing 0 or one n n{x}              to match the string containing the sequence of x N. N{x,} x is a positive integer. The preceding pattern n is matched at least X times consecutively. N{x,y} x and y are positive integers. The preceding pattern n appears consecutively at least X times, and matches at most Y times. n$    matches any string that ends with N. ^n   matches any string ending with N. =n
?! N

---of JavaScript objects RegExp

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.