Say I have this single string, here I denote spaces (" ") with ^
^^quick^^^\n
^brown^^^\n
^^fox^^^^^\n
What regular expression to use to remove trailing spaces with .replace()?
using replace(/\s+$/g, "") not really helpful since that only removes the spaces
on the last line with "fox".
Going through other questions I found that replace(/\s+(?:$|\n)/g,"") matches the right sections
but also gets rid of the new line characters but I do need them.
So the perfect result will be:
^^quick\n
^brown\n
^^fox\n
(only trailing spaces are removed; everything else stays)