Briefly describe the use of regular expressions in JavaScript, javascript Regular Expressions

Source: Internet
Author: User

Briefly describe the use of regular expressions in JavaScript, javascript Regular Expressions

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

The RegExp class in JavaScript represents regular expressions, strings, and regular expression definitions, and uses regular expressions for powerful pattern matching and searching and replacing text functions.
Syntax:

You can use RegExp () to construct a regular expression:

var pattern = new RegExp(pattern, attributes);or simplyvar pattern = /pattern/attributes;

Here is a description of the parameters:

  • Pattern: a string that specifies the pattern of a regular expression or other regular expressions.
  • Attributes: contains any "g", "I", and "m" attributes that specify the global, an optional string, case-insensitive and matching.

Brackets:

Brackets ([]) are special when used in the context of a regular expression. They are used to find the range of characters.

The range shown above is general. You can also use the range [0-3] to match any decimal number through 3 from 0, or the range [B-v] matches any lowercase letter, from B to v
Qualifier:

The frequency or Character Sequence in square brackets and the position of a single character can be expressed by a special character. Each special character has a specific meaning. In + ,*,?, And the $ flag both follow a character sequence.
Example:

The following example clears the concept of matching characters.

Literal characters:

The metacharacter is only followed by a backslash. It is used to make the combination contain letters with special meanings.

For example, you can use the '\ d' metacharacters to search for a large total amount of currency:/([\ d] +) 000/. Here \ d searches for any string of numeric characters.

The following are metacharacters that can be used in Perl-style regular expressions.

Modifier

Several modifiers are available, making work and regular expressions much easier, such as case sensitivity and searching for multiple rows.

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.