匹配所有带括号的字符串:
$text = '[This] is a [test] string, [eat] my [shorts].';preg_match_all("/[[^]]*]/", $text, $matches);var_dump($matches[0]);如果要不带括号的字符串:
$text = '[This] is a [test] string, [eat] my [shorts].';preg_match_all("/[([^]]*)]/", $text, $matches);var_dump($matches[1]);不带括号的替代版本,较慢的匹配版本(使用“ *”代替“ [^]”):
$text = '[This] is a [test] string, [eat] my [shorts].';preg_match_all("/[(.*?)]/", $text, $matches);var_dump($matches[1]);


