我需要某种方式来捕获方括号之间的文本。因此,例如,以下字符串:[This] is a [test] string, [eat] my [shorts].可用于创建以下数组:Array ( [0] => [This] [1] => [test] [2] => [eat] [3] => [shorts] )我有以下正则表达式,/\[.*?\]/但它仅捕获第一个实例,因此:Array ( [0] => [This] )如何获得所需的输出?请注意,方括号是从不嵌套的,因此不必担心。
2 回答
MM们
TA贡献1886条经验 获得超2个赞
奇怪的是,我现在得到以下信息:Array ( [0] => Array ( [0] => [This] [1] => [test] [2] => [eat] [3] => [shorts] ) [1] => Array ( [0] => This [1] => test [2] => eat [3] => shorts ) )
- 2 回答
- 0 关注
- 587 浏览
添加回答
举报
0/150
提交
取消