问题
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