JavaScript RegExp \r meta character

Definition and usage

\r Match the carriage return character with a meta character.

Example

Search for the carriage return character in the string:

let text = "Visit CodeW3C.com.\rLearn Javascript.";
let pattern = /\r/;

Try it yourself

Syntax

new RegExp("\\r")

Or abbreviated as:

/\r/

Browser support

/\r/ It is an ECMAScript1 (ES1) feature.

All browsers fully support ES1 (JavaScript 1997):

Chrome IE Edge Firefox Safari Opera
Supported Supported Supported Supported Supported Supported

Regular expression search methods

In JavaScript, regular expression text search can be completed using different methods.

UsagePattern (pattern)As regular expressions, these are the most commonly used methods:

Example Description
text.match(pattern) String method match()
text.search(pattern) String method search()
pattern.exec(text) RexExp method exec()
pattern.test(text) RexExp Method test()