相当于javascript中特定的php preg_replace

时间:2012-11-19 00:36:10

标签: php javascript preg-replace

JS中这个特定的php preg替换是否等效?

preg_replace('/[\n]{2,}/', "\n", "Hi,\nHow are you?\n\n\nI am just testing");

谢谢!

1 个答案:

答案 0 :(得分:0)

它基本相同,但你必须提供g标志:

var theString = "Hi,\nHow are you?\n\n\nI am just testing";

theString = theString.replace(/\n{2,}/g, '\n');