Convert new line letter to <br> using replace method - Node.js String

Node.js examples for String:HTML String

Description

Convert new line letter to <br> using replace method

Demo Code

String.prototype.nl2br = function() {
  return String(this).replace(/([^>\r\n]?)(\r\n|\n\r|\r|\n)/g, '$1<br />$2');
}

Related Tutorials