Javascript Regexp object attributes, methods, and applications

Source: Internet
Author: User

Javascript provides a Regexp object to perform operations and functions on regular expressions. Each regular expression pattern corresponds to a Regexp instance. You can create an instance of the Regexp object in two ways.

Use Regexp's explicit constructor. Syntax: New Regexp ("pattern" [, "Flags"]).
Use Regexp's implicit constructor in plain text format:/pattern/[flags].
The pattern part is required for the regular expression pattern text to be used. In the first method, the pattern part exists as a javascript string and must be enclosed by double quotation marks or single quotation marks. In the second method, the pattern part is nested between two, quotation marks are not allowed.
The flags part sets the Flag Information of the regular expression, which is optional. If the flags part is set, it exists as a string in the first method; in the second method, it follows the last "/" character in the text form. Flags can be a combination of the following flag characters.
G is the global flag. If this flag is set, the search and replacement operations on a text will take effect for all matching parts of the text. If this flag is not set, only the first matched content is searched and replaced.
I is a case-insensitive flag. If this flag is set, Case sensitivity is ignored during Matching and comparison.
M is a multiline flag. If this flag is not set, the metacharacter "^" only matches the start position of the searched string, the metacharacter "$" only matches the end position of the string to be searched. If this flag is set, "^" can also match the position after "\ n" or "\ r" in the searched string (that is, the beginning of the next row, "$" can also match the position after "\ n" or "\ r" in the searched string (that is, the end of the next row.
Code8.1 is an example of creating a regular expression.
Code 8.1 create a regular expression: 8.1.htm

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.