[英]Replace multiple new lines only
I am trying to do something kind of unusual. 我想做一些与众不同的事情。 I want to replace multiple new lines with two new lines.
我想用两个新行替换多个新行。 There are plenty of questions like that but not exactly, see:
有很多这样的问题,但不完全是这样,请参阅:
Hello\\n\\n\\nWorld\\n\\n\\n\\n!
Should become 应该成为
Hello\\n\\nWorld\\n\\n!
This however 然而这
Hello\\nWorld\\n!
Should stay the same. 应该保持不变。 The problem with my regex is that it replaces single new lines with two.
我的正则表达式的问题是它用两个替换单个新行。
preg_replace('"(\\r?\\n)+"', "\\n\\n", $somevar)
这样的事情?
preg_replace('"(\r?\n){2,}"', "\n\n", $somevar)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.