我正在寻找php中的正则表达式,而没有达到我的目标... 这是我的字符串:
$params = [
AdsInsightsFields::IMPRESSIONS,
AdsInsightsFields::INLINE_LINK_CLICKS,
AdsInsightsFields::SPEND,
AdsInsightsFields::CLICKS,
AdsInsightsFields::IMPRESSIONS,
AdsInsightsFields::REACH,
AdsInsightsFields::GENDER_TARGETING
];
$cursor = $this->Entity->getInsights($params, ['end_time' => (new \DateTime('now'))->getTimestamp()]);
我想用引号将带有换行符的句段检索,而不用引号将不带换行符的段检索出来。
这是我当前的REGEX:
$string = 'xxxxxxxxxxxx "segment
to
recovered with line breaks" xxxxx "other segment without line break" xxxx';
你能把我带走吗?
答案 0 :(得分:0)
使用积极的前瞻匹配换行符:
$string = 'xxxxxxxxxxxx "segment
to
recovered with line breaks" xxxxx "other segment without line break" xxxx';
preg_match_all('/"(?=[^"]*\R)[^"]*"/', $string, $match);
print_r($match);
(?=[^"]*\R)
部分确保比赛中有换行符。
输出:
Array
(
[0] => Array
(
[0] => "segment
to
recovered with line breaks"
)
)