开发者

Regex to find consecutive new lines separated by spaces

I'm using str_replace("\n\n"); to fi开发者_JAVA百科nd any two consecutive new lines \n but the problem is the text I'm working with isn't uniform. The new lines aren't aways back to back. They could be separated by any number of spaces or even a tab (found one). Don't like to use regex that much, but looks like I may need one here.


Try this:

$output = preg_replace('/\n\s*\n/s', '', $input);


This should be a fairly simple regex if all you want to do is replace two line breaks with one.

preg_replace("/\n[ \t]*\n/is", "\n", $inputString);

The [ \t]* will match zero or more spaces or tabs between the line feeds.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜