Regular expressions in JavaScript

Source: Internet
Author: User

How to create

var reg=/\s/var reg=New RegExp ('\\s')//need to be escaped

Matching principle

All letters and numbers are matched by literal means

Special symbols need to be escaped with a backslash (\) as a prefix

Match character

[...] Match any of the characters in parentheses

[^...] ^ as the first character in the left parenthesis, for example: [^ABC] means all characters except A,b,c

\w equivalent to [a-za-z0-9] \w equivalent to [^a-za-z0-9]

\s any Unicode whitespace character \s non-whitespace

\d any ASCII number, equivalent to [0-9] \d takes a character other than 0-9

[\b] backspace direct volume

Multiple matches

{N,m} matches the number of occurrences of the previous item , greater than or equal to n, less than or equal to M

{n} matches n times

{N,} matches at least n times

? Equivalent to {0,1}

+ equivalent to {1,}

* Equivalent to {0,}

Specify a matching location

^ Start of matching string

$ match End of string

\s matches the word boundary, \s the opposite, for example:

The (? =p) 0 wide forward assertion requires that the next characters all match p (?! p) on the contrary

Modifier

At the end/outside

I pattern matching is case insensitive

G Global Match

M multi-line pattern matching, example:

Select, sublet, quote

| Select modifier, match left to right by expression, match to left, right mismatch

(...) combinations, combining several items into 1 units, which can be referenced by \ n (?...) Group only, do not participate in references, can refer to return results

\ n used to refer to the previous (... ) matches

Regular expressions in JavaScript

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.