-2

JS中这个特定的php preg替换是否有等价物?

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

谢谢!

4

1 回答 1

0

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

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

theString = theString.replace(/\n{2,}/g, '\n');
于 2012-11-19T00:38:09.410 回答