Javascript examples for RegExp:Property
The source property returns the text of the RegExp pattern.
Type | Description |
---|---|
String | The text of the RegExp pattern |
The following code shows how to return the text of the RegExp pattern:
<!DOCTYPE html> <html> <body> <button onclick="myFunction()">Test</button> <p id="demo"></p> <script> function myFunction() {//from w w w . jav a 2 s .c om var str = "Visit java2s.com"; var patt1 = /book2s/g; var res = "The text of the RegExp is: " + patt1.source; document.getElementById("demo").innerHTML = res; } </script> </body> </html>