我有这个示例字符串
[can be anything here %+^-_][can be anything here %+^-_][can be anything here %+^-_][can be anything here %+^-_][can be anything here %+^-_][can be anything here %+^-_][can be anything here %+^-_][can be anything here %+^-_]
我的模式是(\[[^\]]+\])
结果我得到了这个
(
[0] => Array
(
[0] => [can be anything here %+^-_]
[1] => [can be anything here %+^-_]
[2] => [can be anything here %+^-_]
[3] => [can be anything here %+^-_]
[4] => [can be anything here %+^-_]
[5] => [can be anything here %+^-_]
[6] => [can be anything here %+^-_]
[7] => [can be anything here %+^-_]
)
[1] => Array
(
[0] => [can be anything here %+^-_]
[1] => [can be anything here %+^-_]
[2] => [can be anything here %+^-_]
[3] => [can be anything here %+^-_]
[4] => [can be anything here %+^-_]
[5] => [can be anything here %+^-_]
[6] => [can be anything here %+^-_]
[7] => [can be anything here %+^-_]
)
)
问题 1
为什么结果有两个数组?无论如何,这没什么大不了的,但我想知道。
问题 2
如何仅使用正则表达式摆脱每个数组值开头和结尾的括号。像这样。
[0] => Array
(
[0] => can be anything here %+^-_
[1] => can be anything here %+^-_
[2] => can be anything here %+^-_
[3] => can be anything here %+^-_
[4] => can be anything here %+^-_
[5] => can be anything here %+^-_
[6] => can be anything here %+^-_
[7] => can be anything here %+^-_
)