Description of JavaScript Regular expressions _ regular expressions

Source: Internet
Author: User

Overview

A regular expression is a set of rules that are declared in advance to match characters in a string.

Basic syntax

Metacharacters

In the pattern of regular expressions, there are some characters that have special meaning and are called meta characters. Metacharacters are matched for a single character.

\w match uppercase and lowercase characters and numbers 0 to 9 of any and underscore, equivalent to [a-za-z0-9_]

\w does not match the size of the English character and the number 0 to 9 of any one, equivalent to [^a-za-z0-9_]

\s matches any whitespace character, equivalent to [\f\n\r\t\v]

\s matches any non-white-space character, equivalent to [^\s]

\d matches any single number from 0 to 9, equivalent to [0-9]

\d does not match any single number from 0 to 9, equivalent to [^0-9]

[\U4E00-\U9FA5] matches any single Chinese character (Unicode encoding is used here to denote Chinese characters)

Defining character

The more common regular expression qualifier is the double slash/regex/

The concept of atoms

The atoms in the regular expression are divided into visible atoms and invisible atoms.

[\f\n\r\t\v] belongs to invisible atoms, others represent visible atoms

Quantifiers

\* matches 0 to multiple metacharacters, equal to {0,}

? Matches 0 to 1 metacharacters, equivalent to {0,1}

{n} matches n-ary characters

{N,} matches at least n metacharacters

{N,m} matches n to M metacharacters

\+ matches at least 1 metacharacters, equal to {1,}

Boundary

\b Match word boundaries

^ string must start with the specified character

The $ string must end with the specified character

Capturing groupings

In regular expressions, use () to organize several units (which can be characters, regular expressions) together to become a self-contained unit.

In regular expressions, groupings are grouped into capture groupings and non-capture groupings.

/(Pattern)/flags

Mode correction

Greedy/lazy, ignoring case, ignoring whitespace characters

Working with scenes

form validation, template engine

The above mentioned is the entire content of this article, I hope you can enjoy.

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.