I am trying to replace all multiplines with single line in a string in javascript but none is working . Below is my code :
var str=inputList.replace(/\n/gm,"\n");
input e.g.
abc,def <3 newlines>
xyz <1 newline>
opp
Expected output:
abc,def <1 newline>
xyz
opp
Actual output:
abc,def<3 newlines>
xyz<1 newline>
opp
Any help is appreciated.
\nwith one\n…var str=inputList.replace(/\n+/gm,"\n");???? I am confused with the final output... So if there is only one, than you replace it with no line breaks?var str=inputList.replace(/\n{2,}/g,"\n");. If that does not work, try alsovar str=inputList.replace(/(\r?\n|<br\s*\/?>){2,}/g,"\n");.