JavaScript RegExp Regular Expressions (1/5)

Source: Internet
Author: User
Tags regular expression

Direct volume syntax

/pattern/attributes

To create the syntax for a RegExp object:
Copy code code as follows:
var obj=new regexp (pattern,attributes);

Case 1:
Copy code code as follows:
var pattern=/a/;
document.write (Pattern.exec ("Asdas"));

Case 2:
Copy code code as follows:
var obj=new regexp ("a");
document.write (Obj.exec ("Asdas"));


The execution results of Case 1 and Case 2 are the same;
Parameters
Parameter pattern is a string that specifies the schema or other regular expression of the regular expression.

The parameter attributes is an optional string that contains the property "G" (performs a global match lookup for all matches rather than stopping after the first match is found.) , "I": Performs a case-insensitive match. and "M": Perform multiple line matches. , used to specify global matches, case-sensitive matches, and multiple line matches, respectively. The M attribute is not supported until ECMAScript is standardized. If pattern is a regular expression, rather than a string, you must omit the argument.

return value
A new RegExp object with the specified pattern and flags. If parameter pattern is a regular expression instead of a string, the RegExp () constructor creates a new RegExp object with the same pattern and flags as the specified regexp.

If you do not use the new operator and RegExp () as a function call, its behavior is the same as when called with the new operator, except that when pattern is a regular expression, it returns only the formula and no longer creates a new RegExp object.

Home 1 2 3 4 5 last
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.