繁体   English   中英

REGEX 在 php 中带有换行符

[英]REGEX with line breaks in php

我正在寻找 php 中的正则表达式而没有达到我的目标......这是我的字符串:

$string = 'xxxxxxxxxxxx "segment

to

recovered with line breaks" xxxxx "other segment without line break" xxxx';

我想检索带换行符的引号中的段,而不检索不带换行符的引号中的段。

这是我当前的正则表达式:

preg_match('/\"[^\"$]*\"/', $string, $match);

你能带我离开那里吗?

使用正向前瞻来匹配换行符:

$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"
        )

)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM