RegExp () in JavaScript, direct amount of regular expression

Source: Internet
Author: User
Tags regular expression

Regular Expressions in JavaScript:
Let's start with a brief description of regular expressions in JavaScript. The ECMAScript v3 standardizes JavaScript Regular Expressions. JavaScript 1.2 implements a subset of the regular expressions required by the ECMAScript V3, and JavaScript 1.5 implements the complete standard. JavaScript's regular expressions are entirely based on the regular expression tools of the Perl programming language, so if you've ever used a Perl language, what I'm about to introduce is definitely a piece of cake for you. Specifically, this is:
JavaScript 1.2 implements a regular expression for Perl 4, and JavaScript 1.5 implements a large subset of the regular expressions of Perl 5.
To define a regular expression of JavaScript with the RegExp () constructor:
In JavaScript, regular expressions are represented by the RegExp object table. Based on what we've described earlier, you can use the RegExp () constructor to create a RegExp object.
The constructor RegExp () has one or two string arguments, and it creates a new RegExp object. The first parameter of the constructor is the string that contains the body of the regular expression, the text that appears between the diagonal pairs in the direct amount of the regular expression that is described later. The second parameter is optional. If this parameter is provided, it shows the flag of the regular expression, which is described in the following log (please be concerned).
Use the RegExp () constructor to create an example of a regular expression:
Defines a global, nine-digit regular expression

var pattern = new RegExp ("\d{9}", "G"); a regular expression that defines JavaScript in direct quantity:
JavaScript also provides the syntax for direct amounts of regular expressions, making it easier for you to create JavaScript regular expressions. It is defined as a character that is contained between a pair of slashes (/). Generally, when writing a JS script, the more common way to create regular expressions is by using regular expression direct volume definition.
To create a regular expression sample with the direct amount of a regular expression:

//Defines a global, nine-digit regular expression
var pattern =/d{9}/:
Whether the regular expression is direct or regular expressions use characters to represent escape sequences, so when you take a regular expression as a When a string literal is passed to RegExp (), all characters must be replaced with \. For example, you can see an example of a JavaScript regular expression that I defined with the RegExp () constructor.

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.