我需要一些方法来捕获方括号之间的文本。例如,以下字符串:
[This] is a [test] string, [eat] my [shorts].
可用于创建以下数组:
Array (
[0] => [This]
[1] => [test]
[2] => [eat]
[3] => [shorts]
)
我有以下正则表达式,/\[.*?\]/
但它只捕获第一个实例,所以:
Array ( [0] => [This] )
我怎样才能得到我需要的输出?请注意,方括号从不嵌套,所以这不是问题。