JSFiddle - React, Tailwind, and code Playground
by Tom Randolph
HTML
<textarea>Option 1
Option 2
Option 3</textarea>
<button>Replace linebreaks</button>
CSS
textarea{
width: 400px;
height: 250px;
}
JavaScript
document.getElementsByTagName( 'button' )[0].onclick = function(){ replaceLinebreaks() };
function replaceLinebreaks(){
var textarea = document.getElementsByTagName( 'textarea' )[0];
textarea.value = textarea.value.replace( /(?:\r?\n)+/gm, '\n' ).replace( /^\s*/gm, '' );
}