Javascript examples for String:match
The match() method matches a string against a regular expression, and returns the matches, as an Array object.
Parameter | Description |
---|---|
regexp | Required. The value to search for, as a regular expression. |
An Array, containing the matches, one item for each match, or null if no match is found
The following code shows how to Search a string for "ain": The result of res will be an array with the values:
<!DOCTYPE html> <html> <body> <button onclick="myFunction()">Test</button> <p id="demo"></p> <script> function myFunction() {/*from ww w.j a va 2s . com*/ var str = "rain this is a test rain pain plain"; var res = str.match(/ain/gi); document.getElementById("demo").innerHTML = res; } </script> </body> </html>