我有一些类似于电子邮件数据的输入数据,因为长行被换行到下一行。例如:
robot-useragent: ABCdatos BotLink/1.0.2 (test links)
robot-language: basic
robot-description: This robot is used to verify availability of the ABCdatos
directory entries (http://www.abcdatos.com), checking
HTTP HEAD. Robot runs twice a week. Under HTTP 5xx
error responses or unable to connect, it repeats
verification some hours later, verifiying if that was a
temporary situation.
该robot-description
字段对于一行来说“太长”,并且被换行到下一行。为了帮助解析这些数据,我想提出一个正则表达式,可用于preg_replace()
替换以下条件:
- 换行符后跟空格
- 不替换换行符后跟其他换行符
示例输出:
robot-description: This robot is used to verify availability of the ABCdatos directory entries (http://www.abcdatos.com), checking HTTP HEAD. Robot runs twice a week. Under HTTP 5xx error responses or unable to connect, it repeats verification some hours later, verifiying if that was a temporary situation.
我是 RegEx 的新手。我怎样才能建立这样的表达?如果您选择回答,请在表达式中包含对组件的简要说明。我真的很想学习如何做这些。
我从这个开始: \n([^\S])*
它很接近。 http://codepad.org/iMObpgFX