Example
Search for a carriage return character in a string:
var str = "Visit w3ii.\rLearn Javascript.";
var patt1 = /\r/;
The marked text below shows where the expression gets a match:
Visit w3ii.\rLearn Javascript.
Try it Yourself »
Definition and Usage
The \r metacharacter is used to find a carriage return character.
\r returns the position where the carriage return character was found. If no match is found, it returns -1.
Browser Support
Expression | |||||
---|---|---|---|---|---|
\r | Yes | Yes | Yes | Yes | Yes |
Syntax
new RegExp("\\r")
or simply:
/\r/
< JavaScript RegExp Object