Regular expression Regular expression detailed (II.)

Source: Internet
Author: User
Tags definition constructor expression reference regular expression
Detailed description of regular regular expressions of express| (II.)

The following are new objects that are not regular expressions see the corresponding JavaScript object's Properties $_ Property Reference Input $* property
Reference Multiline $& Property Reference Lastmatch $+ Property Reference Lastparen $ ' property
Reference Leftcontext $ ' Property Reference Rightcontext compile method to compile regular expression objects during script run
Methods belonging to RegExp provide syntax in JavaScript 1.2, NES over 3.0 versions:
Regexp.compile (pattern[, flags]) in number: RegExp the name of a regular expression, either a variable name or a string of text.
The definition text of the pattern regular expression. Flags, if specified, can be one of the following: "G": match all possible strings
"I": Ignores Case "GI": matches all possible strings and ignores case descriptions:
Use the Compile method to compile a regular expression created with the RegExp constructor function. Such
Forces the regular expression to compile only once, not every time a regular expression is encountered. When you confirm that the regular expression is capable of
You can use the compile method to compile it (after you get its matching pattern) so that it is repeated multiple times in your script.
You can also use the Compile method to change the regular expression during run time. For example, if the regular expression is changed,
You can use the compile method to recompile the object to improve efficiency.
Using this method will change the value of the source, global, and Ignorecasesource properties of the regular expression. Constructor
Indicates the function that establishes the object prototype. Note that the value of this property is provided by the function itself, not by a string containing the RegExp name.property.
In JavaScript 1.1, NES 2.0 version provides ECMA version ECMA-262 description: Reference object.constructor.
The Exec method runs a matching search in the specified string. Returns an array of results. It's a regexp way.
In JavaScript 1.2, NES version 3.0 provides syntax: Regexp.exec ([str]) regexp ([str])
Parameters: RegExp, the name of the regular expression, can be a variable name or a text definition string.
STR, to match the string of the regular expression, if omitted, the value of the regexp.input is used.
Description: As in the syntax description, the Exec method of a regular expression can be invoked directly (using Regexp.exec (str)) or indirectly (using RegExp (str)).
If you're just running to find out if it matches, you can use string search methods.
If the match succeeds, the Exec method returns an array and updates the value of the regular Expression object property and the predefined regular expression object, RegExp. If the match fails, the Exec method returns NULL.
Take a look at the following example: The return value of the script: Object attribute/index Description Example
MyArray

MyArray content ["DBBD", "BB", "D"]
Index
0-based matching index 1
Input
Raw String CDBBDBSBZ
[0]
Last-matched character dbbd
[1], ... N
A matching string enclosed in parentheses, if any. Does not limit the number of parentheses. [1] = BB
[2] = d
Myre
Lastindex
Index value of starting next match operation 5
IgnoreCase
Indicates whether "I" is used to ignore case true
Global
Indicates whether the "G" tag is used to match all possible string true
Source
A text string that defines the pattern D (b +) (d)
Regexp
lastmatch$&
Last-matched character dbbd
Leftcontext$\q
Latest Match substring C in front
rightcontext$ '
Substring BSBZ after the latest match
$, ...
The matching substring within the parentheses, if any. The number of parentheses is unrestricted, but RegExp can only retain the last 9 $ = BB
$ = d
Lastparen $+
The last matching substring with parentheses, if any, D

If your regular expression uses the "G" tag, you can use the Exec method multiple times to match the same string consecutively. When you do this
, the new match starts in a substring determined by the Lastindex property value of the regular expression. For example, suppose you use the following script:
This script shows the following results: Found ABB. Next Match starts at 3
Found AB. Next Match starts at 9 example:
In the following example, the user enters a name, and the script performs a matching operation based on the input. Then check the array to see if it matches the other user's name.
This script assumes that the last name of the registered user has been stored in array A and may be obtained from a database.



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.