【发布时间】:2026-02-24 05:40:01
【问题描述】:
我很难找到具有 preg_match_all 模式的特定对象。我有一个文本。但我只想找到一个具体的
就像我有一串文本
sadasdasd:{"website":["https://bitcoin.org/"]tatic/cloud/img/coinmarketcap_grey_1.svg?_=60ffd80');display:inline-block;background-position:center;background-repeat:no-repeat;background-size:contain;width:239px;height:41px;} .cqVqre.cmc-logo--size-large{width:263px;height:45px;}
/* sc-component-id: sc-2wt0ni-0 */
但是我只需要找到“网站”:[“https://bitcoin.org/”]。网站是动态数据。比如网站可以是google "website":["https://google.com/"]
现在我有这样的东西。那只是返回大量的网址。我只需要具体的
$parsePage = "sadasdasd:{"website":["https://bitcoin.org/"]tatic/cloud/img/coinmarketcap_grey_1.svg?_=60ffd80');display:inline-block;background-position:center;background-repeat:no-repeat;background-size:contain;width:239px;height:41px;} .cqVqre.cmc-logo--size-large{width:263px;height:45px;}
/* sc-component-id: sc-2wt0ni-0 */";
$pattern = '/
\"website":[" # [ character
(?: # non-capturing group
[^{}] # anything that is not a { or }
| # OR
(?R) # recurses the entire pattern
)* # previous group zero or more times
\"] # ] character
/x';
preg_match_all($pattern, $parsePage, $matches);
print_r($matches[0]);
【问题讨论】:
-
方括号必须转义。
标签: php regex preg-match-all