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.
我正在尝试做一些不寻常的事情。我想用两条新线替换多条新线。有很多这样的问题,但不完全是,请参阅:
Hello\n\n\nWorld\n\n\n\n!
应该成为
Hello\n\nWorld\n\n!
然而这
Hello\nWorld\n!
应该保持不变。我的正则表达式的问题在于它用两个新行替换了单个新行。
preg_replace('"(\r?\n)+"', "\n\n", $somevar)
像这样的东西?
preg_replace('"(\r?\n){2,}"', "\n\n", $somevar)