RegExp.exec()

JavaScript 1.2+, JScript 3.0+ Nav4+, NES3+, IE4+ Syntax

							regexp.exec(string)

Description

The exec() method of the RegExp object executes the search for a match in a specified string. The results are returned in an array. The string passed contains the string the regular expression is trying to match in.

Example

In Listing 6.215, you see how the exec() method is used. A regular expression is defined and executed on the string using the exec method.

Listing 6.215 Example of exec() Method
 <html> <body> <script language="JavaScript"> <!–– Hide // checks for the pattern "xyz" in str. If found, then // output written to document indicating that it was found and // displays the index it was found in the string. myRe=/xyz*/g; ...

Get Pure JavaScript now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.