Latest web development tutorials

RegExp \ n metacharacter

RegExp Object Reference JavaScript RegExp Object

Definition and Usage

\ N metacharacter used to find line breaks.

\ N newline return position is found. If no match is found, it returns -1.

grammar

new RegExp("\n")

或者更简单方式:

/\n/


Browser Support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support \ n metacharacter


Examples

Examples

Search string newline character:

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

The marked text below shows where the expression gets a match:

Visit W3Cschool. \n Learn Javascript.

try it"


RegExp Object Reference JavaScript RegExp Object