首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >双秒托架端锚

双秒托架端锚
EN

Stack Overflow用户
提问于 2021-05-02 10:10:48
回答 1查看 41关注 0票数 0

我需要只与passengerData匹配的数据。我试过像下面这样做,但它不能正常工作

代码语言:javascript
复制
$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);
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-05-06 22:52:43

使用

代码语言:javascript
复制
/"passengerData"\s*:\s*({.*?}});$/m

正则证明$matches[1]必须有您想要的数据。

解释

代码语言:javascript
复制
--------------------------------------------------------------------------------
  "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
                           string
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/67355139

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档