[英]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.