Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
JS中这个特定的php preg替换是否有等价物?
preg_replace('/[\n]{2,}/', "\n", "Hi,\nHow are you?\n\n\nI am just testing");
谢谢!
基本相同,但您必须提供g标志:
g
var theString = "Hi,\nHow are you?\n\n\nI am just testing"; theString = theString.replace(/\n{2,}/g, '\n');