Javascript examples for RegExp:Method
The test() method tests for a match in a string.
Parameter | Description |
---|---|
string | Required. The string to be searched |
Type | Description |
---|---|
Boolean | Returns true if it finds a match, otherwise it returns false |
The following code shows how to Search a string for the character "e":
<!DOCTYPE html> <html> <body> <button onclick="myFunction()">Test</button> <p id="demo"></p> <script> function myFunction() {//w w w . java2 s. c o m var str = "The following code shows how to test"; var patt = new RegExp("e"); var res = patt.test(str); document.getElementById("demo").innerHTML = res; } </script> </body> </html>