JS中这个特定的php preg替换是否等效?
preg_replace('/[\n]{2,}/', "\n", "Hi,\nHow are you?\n\n\nI am just testing");
谢谢!
答案 0 :(得分:0)
它基本相同,但你必须提供g
标志:
var theString = "Hi,\nHow are you?\n\n\nI am just testing";
theString = theString.replace(/\n{2,}/g, '\n');