-3
some code here

some code here

to

some code here
some code here

What is the regex to remove the spaces between each paragraph? I've been searching for a while but I couldn't find one. Some of the results would be:

some code heresome code here

but it isn't the one i'm trying to find

ronsic
  • 205
  • 4
  • 15

2 Answers2

0

Replace multiple \n with single \n:

var str = `some code here

some code here`;
console.log(str);
str = str.replace(/\n{2,}/g,'\n');
console.log(str);
Mamun
  • 66,969
  • 9
  • 47
  • 59
0

replace 1 or more \n (newline) characters with a single newline character:

const input = `some code here

some code here


some code here
some code here




some code here`;
const output = input.replace(/\n+/g, '\n');
console.log(output);
CertainPerformance
  • 356,069
  • 52
  • 309
  • 320