A brief introduction to the use of the regular expressions in JavaScript

Source: Internet
Author: User
Tags modifiers regular expression

This article mainly introduces the use of the JavaScript in the regular expression, the regular expression is the important knowledge of JS advanced Learning, this article briefly describes the support for the regular expression JS, the need for friends can refer to the

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

The RegExp class of JavaScript represents regular expressions and string and regular expression definitions, using regular expressions for powerful pattern matching and searching and replacing text functionality.

Grammar:

A regular expression can construct such a definition with RegExp ():

?

1 2 3 4 5 var pattern = new RegExp (pattern, attributes); or simply var pattern =/pattern/attributes;

Here is the description of the parameter:

Pattern: A string that specifies patterns for regular expressions or other regular expressions.

Attributes: Contains any "G", "I", and "m" attributes specify Global, an optional string, case-insensitive and matched.

Brackets:

parentheses ([]) have special meaning when used in the context of a regular expression. They are used to look up the range of characters.

The range shown above is general; You can also use the range [0-3], by 3 matches any decimal number from 0, or range [b-v] matches any lowercase letter, from B to V

Qualifier:

The frequency or the position of a character sequence in square brackets with a single character can be represented by a special word. Each special character has a specific connotation. In +, *,?, and $ flags are followed by a sequence of characters.

Example:

The following example clears the concept of matching characters.

Literal characters:

The metacharacters is simply preceded by a backslash, which is the function of making a combination of alphabetic characters with special meanings.

For example, you can use the ' d ' character to search for a large sum of money:/([D]+) 000/, where D will search for any string of numeric characters.

The following is a meta character, a list that can be used in a Perl-style regular expression.

Modifiers

Several modifiers are available to make working with regular expressions much easier, such as capitalization, searching for multiple rows, and so on.

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.