RegExp \r Metacharacter - Javascript RegExp

Javascript examples for RegExp:Metacharacter

Description

The \r metacharacter matches a carriage return character.

If no match is found, it returns -1.

The following code shows how to Search for a carriage return character in a string:

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 a2 s. c  o  m
    var str = "Visit java2s.com.\rLearn JavaScript.";
    var patt1 = /\r/;
    var result = str.search(patt1);
    document.getElementById("demo").innerHTML = result;
}
</script>

</body>
</html>

Related Tutorials