Because chris isn't using look arounds with his preg_match_all()
pattern, not all substrings are captured.
This will capture all of the substrings (without any unwanted leading/trailing white space characters) using preg_match_all()
: /(?<=\]{2}) ?\K.+?(?=$| \[{2})/
Pattern Demo
var_export(preg_match_all('/(?<=\]{2}) ?\K.+?(?=$| \[{2})/', $input, $out) ? $out[0] : []);
chris' preg_split()
method does not contend with leading and trailing spaces. This is a corrected/refined method (this is my recommended regex method):
var_export(preg_split('/ ?\[{2}QVQ\]{2} ?/', $input, 0, PREG_SPLIT_NO_EMPTY));
This is a non-regex method:
var_export(array_values(array_filter(array_map('trim', explode('[[QVQ]]', $input)), 'strlen')));
Breakdown of non-regex method:
array_values( // reindex the array
array_filter( // unset any empty elements
array_map('trim', // remove leading/trailing spaces from each element
explode('[[QVQ]]', $input) // split on known delimiter
),
'strlen'
)
)