JavaScript \n Metacharacter | RegEx Match New Line

The JavaScript \n metacharacter is used to match new line in specified string using JavaScript regular expression. For example:

HTML with JavaScript Code
<!DOCTYPE html>

   <p id="xyz"></p>

      let myString = "JavaScript is Fun.\nIs not it?";
      let pattern = /\n/;
      document.getElementById("xyz").innerHTML =;

Since the new line character, that is \n is available at index number 18 in the specified string, therefore the output produced by above JavaScript code is 18.

Note: The search() method is used to search a substring (value) in a string using regular expression.

JavaScript Online Test

« Previous Tutorial Next Tutorial »

Follow/Like Us on Facebook

Subscribe Us on YouTube