An example of EXEC function usage in JavaScript _javascript skills

Source: Internet
Author: User

This example describes the use of Exec functions in JavaScript. Share to everyone for your reference. Specifically as follows:

The EXEC function in JavaScript that 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 properties of the global RegExp object 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 is equivalent to no match method for setting global flag (g).

If the global flag is set for a regular expression, exec starts the lookup from the position indicated by the value of lastindex. If the global flag is not set, EXEC ignores the lastindex value and starts the search from 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. The Index property contains the position of the entire substring found to be matched in the lookup string. The Lastindex property contains the next position of the last character in the match.

<script language= "JavaScript" >
function ge (obj)
{
re=/(\w+) \s (\d+)/;
Re.exec (obj.value);
Window.alert (regexp.$1+ "Your Age is" +this.form1.ag.value+regexp.$2);
}
</script>

I hope this article will help you with your JavaScript programming.

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.