I am trying to write a script that updates HTML on the onKeyUp of a textbox of a form. The HTML is basically a preview of what it will look like when the form is submitted and entered into a database.
The problem is, I want to replace all new lines with "<br />\n". So when the user is typing and they hit return it should be replaced with "<br />\n", however, every keystroke after will add another break since the "\n" that I added still matches the regex.
How can I test to only replace the new lines that don't already have a "<br />" in the line?
I have tried this: replace(/[^<br />](\r\n|\r|\n)/g, "<br />\n") but it matches and replaces the character before the new line, too.