I'm doing this (+ JSON.stringify()) for sending linebreaks via ajax to my mysql server:
var newChatComment = varChatComment.replace(/\r\n|\r|\n/g,'\n');
How can I also replace multiple line breaks with two line break and in case of if the line break(s) is(are) at the end ... remove the line break?
- plus in case of only one line break ... keep this line break at one?
Edit: The duplicate example pointed to doesn't consider the fact to remove the line break in case the line break is at the end. So this is a new question