The description and application of the regular expression function of JScript

Source: Internet
Author: User
As a powerful tool for text substitution, search and extraction in pattern matching, the application of regular expression (Regular Expression) has been gradually infiltrated into network development from the UNIX platform, as the server-side/client Script development language JScript, More and more regular expression applications are being incorporated into them to make up for the inadequacy of their ability to deal with the text. Here, we use the JScript5.5 version as an example to summarize the application of regular expressions.
First we need to differentiate between two objects in JScript about regular expressions: Regular expression objects and RegExp objects.
The former contains only the information of a particular regular expression instance, and the latter reflects the attributes of the most recent pattern match through the properties of a global variable.
The former needs to specify a matching pattern before matching, that is, to create an instance of a regular expression object, and then pass it to a string method, or pass a string as an argument to the regular expression instance, which does not need to be created, It is an intrinsic global object, and each successful matching operation result information is saved in the object's properties.
Properties of the RegExp object: Reaction to the results of the most recent successful match
Input: Save execution of matching string (target string searched) (>=ie4)
Index: Save matching first character position *>=ie4)
Lastindex: Holds the position of the next character of the matching string (>=ie4)
Lastmatch ($&): Save a matching string (>=ie5.5)
Lastparen ($+): Saves the last child match of the matching result (the last bracket match) (>=ie5.5)
Leftcontext ($ '): Save all characters before matching substrings in the target string (>=ie5.5)
Rightcontext ($ '): Saves all characters after matching substrings in the target string (>=ie5.5)
$ $: Saves the first 9 child matches in the match (that is, the first 9 parentheses) (>=IE4)
Introduction of Regular Expression objects
1.Regular Expression Object Definition
In the script to use regular expression pattern matching, first waist sets the matching pattern, the method has the following two kinds
(1) rgexp=/pattern*/[flags*]
(2) Rgexp=new RegExp ("pattern", ["flags"])
Attention:
A. The escape characters in the latter pattern "need to be" expressed to offset the meaning of JS "" "" ", otherwise JS first as its escape concept to explain" "after the character.
The B.flags logo has the following (up to JScript 5.5 versions)
G: Set current match as global mode
I: Ignore case detection in matches
M: Multi-line search mode
2.Regular Expression Object Properties
(1) Rgexp.lastindex: matches the position of a character after the result, with Regexp.lastindex

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.