Matches a string with a regular expression, and returns an array containing the results of that search.
SyntaxstringObj.match( rgExp )
The following example illustrates the use of the match method.
var src = "azcafAJAC";
var re = /[a-c]/;
var result = src.match(re);
document.write(result[0] + "<br/>");
var reg = /[a-c]/g;
result = src.match(reg);
for (var index = 0; index < result.length; index++)
{
document.write ("submatch " + index + ": " + result[index]);
document.write("<br />");
}
Remarks
If the match method does not find a match, it returns null. If it finds a match, match returns an array, and the properties of the global RegExp object are updated to reflect the results of the match.
The array returned by the match method has three properties, input , index and lastIndex. The input property contains the entire searched string. The index property contains the position of the matched substring within the complete searched string. The lastIndex property contains the position following the last character in the last match.
If the global flag ( g ) is not set, Element zero of the array contains the entire match, while elements 1 through n contain any submatches. This behavior is the same as the behavior of the exec Method (Regular Expression) when the global flag is not set. If the global flag is set, elements 0 through n contain all matches that occurred.
If the flag i is set, the search is not case-sensitive.
See also Other articlesMicrosoft Developer Network: Article
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4