RegExp source Property - Javascript RegExp

Javascript examples for RegExp:Property

Description

The source property returns the text of the RegExp pattern.

Return Value

Type Description
String The text of the RegExp pattern

The following code shows how to return the text of the RegExp pattern:

Demo Code

ResultView the demo in separate window

<!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>

Related Tutorials