示例:
%body
The family is a central socialization context from early childhood
behavior \cite{dishi-sto2007,hengg-etal1998,johns-etal2005}.
Family management becomes more challenging for parents during the
transition from middle childhood to adolescence. Typically developing
说明:我需要从字符串"%body"
中提取内容,直到第一段。
我使用preg_match( '/%body\\n(.*?)\\n/', $text, $matches );
进行提取。
输出 The family is a central socialization context from early childhood
由于\n
字符在所有行中,我在字符串中得到一行。那么如何使用正则表达式找到索引0处的\n
字符,以便我可以按段提取。
答案 0 :(得分:0)
启用DOTALL修改器以在正则表达式中创建点以匹配偶数换行符。
preg_match( '~(?s)%body\n(.*?)(?:\n\n|$)~', $text, $matches );
从组索引1中获取所需的字符串。
答案 1 :(得分:0)