Javascript regex remove all line breaks after comma

非 Y 不嫁゛ 提交于 2021-02-05 08:34:12

问题


I need a simple regex that will remove all line breaks after comma. right know what I'm doing is removing all

\n/g

what do I need to add in order to remove only after comma? thanks.


回答1:


Use

replace(/,\n/g,"")

For example

"\n\n,\n".replace(/,\n+/g,",")



回答2:


That's really simple. Try this:

/,\n+/g

Online Demo


Full Code:

var str = "first line,\nsecond line,\nalso, it is third line,\nand fourth line";
str = str.replace(/,\n+/g, ',');


来源:https://stackoverflow.com/questions/36154113/javascript-regex-remove-all-line-breaks-after-comma

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!