在JavaScript中删除多个换行符(\ n)

我们为新员工提供入职表格,其中包含需要剥离的多个换行符(行间距为4-5行)。 我想摆脱额外的新行,但仍然用一个\ n来区分块。

例:

New employee
John Doe Employee Number
1234

我目前正在使用text = text.replace(/(\r\n|\r|\n)+/g, '$1'); 但是没有间距就摆脱了所有新行。

 text = text.replace(/(\r\n|\r|\n){2,}/g, '$1\n'); 

使用它,它将删除至少有2个或更多的换行符

更新

关于OP的具体要求我会稍微编辑一下答案。

 text = text.replace(/(\r\n|\r|\n){2}/g, '$1').replace(/(\r\n|\r|\n){3,}/g, '$1\n'); 

我们可以整理正则表达式如下:

 text = text.replace(/[\r\n]{2,}/g, "\n");