Example Analysis of exec function usage in JavaScript and exec instance analysis

Source: Internet
Author: User

Example Analysis of exec function usage in JavaScript and exec instance analysis

This example describes how to use the exec function in JavaScript. Share it with you for your reference. The details are as follows:

The exec function in javaScript runs the search in the string in regular expression mode and returns an array containing the search result.

RgExp.exe c (str)

Parameters:

RgExp is required. A regular expression object that contains the regular expression mode and available flag.

Str is required. The String object or String text to be searched.

Note:

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 attributes of the global RegExp object to reflect the matching result. The 0 element of the array contains the complete match, and the 1st to nelement contains any child match in the match. This is equivalent to the match method without setting the global flag.

If a global flag is set for the regular expression, exec searches for it at the position indicated by the value of lastIndex. If the global flag is not set, exec ignores the value of lastIndex and searches from the starting position of the string.

The array returned by the exec method has three attributes: input, index, and lastIndex. The Input attribute contains the entire searched string. The Index attribute contains the position of the matched substring in the searched string. The LastIndex attribute contains the next position of the last character in the match.

<Script language = "JavaScript"> function ge (obj) {re =/(\ w +) \ s (\ d +)/;re.exe c (obj. value); window. alert (RegExp. $1 + "your age is" + this. form1.ag. value + RegExp. $2) ;}</script>

I hope this article will help you design javascript programs.

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.