String Function match()
Method or Function: match(arg)
Syntax: string.match(arg)
The match() method is used on a string variable or literal, and takes a regular expression pattern as argument to retrieve the matches when matching that string against that regular expression.
If matches were found in the string, the match() method returns an array containing all matched substrings , or null if no match is found.
Example
<script type="text/javascript">
var string="hello everybody,my name is Aspell";
document.write(string.match("Aspell"));
</script>
var string="hello everybody,my name is Aspell";
document.write(string.match("Aspell"));
</script>
If we write,
document.write(string.match("Aspelll"));
Output
nullIf we write,
document.write(string.match("sky"));
Output
null
No comments:
Post a Comment