Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

RegExp \n metacharacter

JavaScript RegExp \n metacharacter

RegExp Object Reference JavaScript RegExp Object


Definition and Usage

The \n metacharacter is used to find newline characters.

\n returns the position where the newline was found. If no match is found, it returns -1.

Syntax

new RegExp("\n")

Or a simpler way:

/\n/


Browser support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support the \n metacharacter


Example

Example

Search for newline characters in the string:

var str="Visit RUNOOB.\nLearn Javascript.";

var patt1=/\n/;

The text marked below shows where the expression found matches:

Visit RUNOOB.

\n

Learn Javascript.

Try it »


RegExp Object Reference JavaScript RegExp Object