我需要只与passengerData匹配的数据。我试过像下面这样做,但它不能正常工作
$getContent='passenger list:
"passengerData":{"id-1":{...},"id-2":{...},...."id-nth":{...}};
flight List:
"flightData":{"id-1":{...},"id-2":{...},...."id-nth":{...}};';
preg_match_all('/"passengerData([^*]+\}})/', $getContent, $matches);发布于 2021-05-06 22:52:43
使用
/"passengerData"\s*:\s*({.*?}});$/m见正则证明。$matches[1]必须有您想要的数据。
解释
--------------------------------------------------------------------------------
"passengerData" '"passengerData"'
--------------------------------------------------------------------------------
\s* whitespace (\n, \r, \t, \f, and " ") (0 or
more times (matching the most amount
possible))
--------------------------------------------------------------------------------
: ':'
--------------------------------------------------------------------------------
\s* whitespace (\n, \r, \t, \f, and " ") (0 or
more times (matching the most amount
possible))
--------------------------------------------------------------------------------
( group and capture to \1:
--------------------------------------------------------------------------------
{ '{'
--------------------------------------------------------------------------------
.*? any character except \n (0 or more times
(matching the least amount possible))
--------------------------------------------------------------------------------
}} '}}'
--------------------------------------------------------------------------------
) end of \1
--------------------------------------------------------------------------------
; ';'
--------------------------------------------------------------------------------
$ before an optional \n, and the end of the
stringhttps://stackoverflow.com/questions/67355139
复制相似问题