One simple way to remove whitespaces in my case is to do like this -
<textarea id="thetext" lines="8" style="width: 100%; height: 8em;">
hello, how are you
i'm fine
And i hope the same from you
</textarea><br>
<button onclick="whitespaces()">Vanish</button>
<script>
function whitespaces() {
var input = document.getElementById("thetext");
input.value = input.value
.replace(/\t{1,}/g, "")
.replace(/\n{3,}/g, '\n\n')
.replace(/ {1,}/g, ' ')
.replace(/^ /gm, '')
.replace(/ $/gm, '')
.replace(/^\n{1,}/g, '')
.replace(/\n{1,}$/g, '');
}
</script>
However I'm trying to achieve the same objective with negative condition. That is by using minus or something like that. As i'm new to js, i'm not familiar with negative conditions. So can anyone tell me how to use negative condition in this case. The code should look something like this -
function whitespaces() {
var input = document.getElementById("thetext");
input.value = input.value.replace(all whitespaces [\s] minus linebreak [\n] and paragraph breaks [\n\n])
}