JavaScript RegExp \nMetacharacter
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/
Or the simpler way:
/\n/
Browser Support
![]()
![]()
![]()
![]()
![]()
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/;
var patt1=/\n/;
BelowmarkedThe text shows the position where the expression obtained a match:
Visit EXAMPLE.\nLearn Javascript.
Try it Yourself »
JavaScript RegExp Object Other Extensions