JavaScript RegExp \nMetacharacter

RegExp 对象参考手册JavaScript RegExp Object

Definition and Usage

The \n metacharacter is used to find a newline character.

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

Syntax

new RegExp("\n")

Or the simpler way:

/\n/


Browser Support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support the \n metacharacter


Example

Example

Search for a newline character in a string:

var str="Visit EXAMPLE.\nLearn Javascript.";
var patt1=/\n/;

BelowmarkedThe text shows the position where the expression obtained a match:

Visit EXAMPLE.\nLearn Javascript.

Try it Yourself »


RegExp 对象参考手册JavaScript RegExp Object Other Extensions