-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
  • 195
  • 3
  • 14

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
  • 62,450
  • 9
  • 45
  • 52
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
  • 313,535
  • 40
  • 245
  • 254