JScript Method-Exec method

Source: Internet
Author: User
Tags array contains expression regular expression version
Js|jscript runs a lookup in a string with a regular expression pattern and returns an array that contains the result of the lookup.

Rgexp.exec (str)

Parameters
Rgexp

Required option. A regular expression object that contains the regular expression pattern and the available flags.

Str

Required option. The string object or string literal in which to perform the lookup.

Description
If the Exec method does not find a match, it returns NULL. If it finds a match, the Exec method returns an array and updates the global REGEXP
Image to reflect the result of the match. The 0 elements of the array contain a complete match, and the 1th to n element contains any of the child matches that appear in the match. This
Corresponds to a match method that does not have a global flag (g) set.

If the global flag is set for a regular expression, exec starts the lookup from the position indicated by the value of lastindex. If no global flag is set, exec suddenly
A slightly lastindex value, starting at the beginning of the string.

The Exec method returns an array that has three properties, namely input, index, and lastindex. The Input property contains the entire string being looked up. Index
property contains the location of the entire substring to be matched in the lookup string. The Lastindex property contains the next bit of the last character in the match
Reset

Example
The following example illustrates the use of the Exec method:

function Regexptest () {
var ver = number (ScriptEngineMajorVersion () + "." + ScriptEngineMinorVersion ())
if (ver >= 5.5) {//test the version of JScript.
var src = "The rain in Spain falls mainly the plain."
var re =/w+/g; Creates a regular expression pattern.
var arr;
while ((arr = re.exec (src))!= null)
document.write (Arr.index + "-" + Arr.lastindex + "T" + arr);
}
else{
Alert ("Please use the updated version of JScript");
}
}
Requirements
Version 3


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.