PHP-Regex在方括号内查找字符串

PHP-Regex在方括号内查找字符串,php,regex,Php,Regex,我有以下示例文本 Some HTML[caption id="attachment_146" align="alignleft" width="450" caption="Annette during 2008 WSOP"]<a href='123'><img src='xxx' /></a>[/caption]More HTML 它似乎能够识别开头标题“tag”请尝试以下操作: $re = "/\\[caption ([^\\]]*)\\]/"; $st

我有以下示例文本

Some HTML[caption id="attachment_146" align="alignleft" width="450" caption="Annette during 2008 WSOP"]<a href='123'><img src='xxx' /></a>[/caption]More HTML
它似乎能够识别开头标题“tag”

请尝试以下操作:

$re = "/\\[caption ([^\\]]*)\\]/"; 
$str = "Some HTML[caption id=\"attachment_146\" align=\"alignleft\" width=\"450\" caption=\"Annette during 2008 WSOP\"][/caption]More HTML"; 

preg_match($re, $str, $matches);
这将返回:

id="attachment_146" align="alignleft" width="450" caption="Annette during 2008 WSOP"
请尝试以下操作:

$re = "/\\[caption ([^\\]]*)\\]/"; 
$str = "Some HTML[caption id=\"attachment_146\" align=\"alignleft\" width=\"450\" caption=\"Annette during 2008 WSOP\"][/caption]More HTML"; 

preg_match($re, $str, $matches);
这将返回:

id="attachment_146" align="alignleft" width="450" caption="Annette during 2008 WSOP"

顺便说一下,我在谷歌上搜索了你的瓷砖,找到了至少10个答案。答案都在索比,就像我在谷歌上搜索你的地砖一样,找到了至少10个答案。答案都在这里