METHOD:  RegExp::exec

object([str]) Netscape Only Feature
This method executes a search for a match in a specified string, returning a result array. (If, however, you simply want to test whether or not there is a match, it is best to use the test method or the method.) For example, the following blocks of code, one for the Internet Explorer browser and the other for Netscape, each execute a search of the string "the fisherman" for a match with the regular expression 'rexp'. If one is found (and in the case of the example it is), then an appropriate message is printed.
Code:Internet Explorer Only Feature
rexp = /[aeiou]/g
myString = "the fisherman"
   match = rexp.exec(myString)
   document.write("Successfully matched " + match)

Code:Netscape Only Feature
rexp = /[aeiou]/g
myString = "the fisherman"
   match = RegExp.lastMatch
   document.write("Successfully matched " + match)

Output:Internet Explorer Only Feature Netscape Only Feature
Successfully matched e
The Netscape browser can call the exec method both directly (object.exec([str])) or indirectly (object([str])), whereas Microsoft Internet Explorer can only call it directly. If no string is declared then the value of RegExp.input is used. If the search fails, the exec method returns null.

Copyright 1999-2001 by Infinite Software Solutions, Inc. All rights reserved.
Trademark Information