JavaScript RegExp \n Metacharacter

The regex "\n" shows the available new line in the input string in JavaScript. If the new line element is available, then the position of the values shows; otherwise "-1" value shows using the search method. We can test, search, and match the required string using this Metacharacter.

Syntax

The syntax is used to show new line elements of the input string.

Description:

  • The new line metacharacter does not need a modifier to operate all values.
  • We can use the regex method with regex patterns and metacharacters.

Supported Browsers

The RegExp \n Metacharacter supports the following browsers supported using the javascript function:

  • Google Chrome
  • Apple Safari
  • Mozilla Firefox
  • Opera
  • Internet Explorer

Examples

The following examples use to search, match, test, and execute new line values using the "\n" regex metacharacter in javascript.

Example 1

The following example shows a test new line metacharacter of the regex in javascript. If the value is available, the test method shows true otherwise false.

Output

The output shows the non-word character of the string.

JavaScript RegExp \n Metacharacter

Example 2

The following example shows the position of the new line metacharacter of the regex in tttttttttt. If a new line value is unavailable, then "-1" shows as an output.

Output

The output shows the position of the new line of the string.

JavaScript RegExp \n Metacharacter

Example 3

The following example shows the position of the new line metacharacter of the regex in JavaScript. If a new line value is unavailable, then "null" is an output.

Output

The output shows the position of the new line of the string.

JavaScript RegExp \n Metacharacter

Example 4

The following example shows the available new line metacharacter of the regex in javascript. If a new line value is available, then the value is replaced with the required input.

Output

The output shows the replacement value of the new line in the string.

JavaScript RegExp \n Metacharacter

Conclusion

The regular expression helps to find new lines in the information using JavaScript methods.

The simple Metacharacter works to validate user-interactive data.






Latest Courses