更新时间:2022-03-08 17:09:14
您可以使用以下正则表达式
[.*?][^]]*]
您的代码将是
<?php
$str = "This is a test string. I want to get value between [this] and [/this]";
$regex = '~[.*?][^]]*]~';
if (preg_match($regex, $str, $m)) {
$yourmatch = $m[0];
echo $yourmatch;
}
?> //=> [this] and [/this]