Javascript examples for RegExp:Method
The exec() method returns the matched text if it finds a match, otherwise it returns null.
Parameter | Description |
---|---|
string | Required. The string to be searched |
Type | Description |
---|---|
Array | An array containing the matched text if it finds a match, otherwise it returns null |
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.j ava 2 s . c o m var str = "The following code shows how to "; var patt = new RegExp("e"); var res = patt.exec(str); document.getElementById("demo").innerHTML = res; } </script> </body> </html>