String.match()
|
|
Syntax |
string.match(regexpression)
|
|
The match() method searches the string for the regular expression passed to the method. |
The regular expression is made up of a pattern and flags. |
The method returns an array containing the matches found in the string. |
See RegExp for how to use the regular expression. |
<html> <script language="JavaScript1.2"> <!-- var myString = new String("This is Mr. Right");
var myRegExp = /sw*/g;
var answerArray = myString.match(myRegExp);
if(answerArray == null){ document.write('No matches were found'); }else{ document.write('The following matches were found: <br>'); for(var i = 0; i < answerArray.length; i++){ document.write(answerArray[i] + '<br>'); } } document.close(); --> </script> </html>
|
|
|
HTML code for linking to this page:
|