RegExp toString Method - Javascript RegExp

Javascript examples for RegExp:Method

Description

The toString() method returns the string value of the regular expression.

Parameters

None.

Return Value

Type Description
String The string value of the regular expression

The following code shows how to return the string value of the regular expression:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<button onclick="myFunction()">Test</button>

<p id="demo"></p>

<script>
function myFunction() {/*w  ww. j  av a 2s .co m*/
    var patt = new RegExp("Hello World", "g");
    var res = patt.toString();
    document.getElementById("demo").innerHTML = res;
}
</script>

</body>
</html>

Related Tutorials