<?php
$re = '/^#%META((?>\R(?!#%(?:META|ENDS)$).*)+)\R#%ENDS$/m';
$str = '#%META
# date: 2022-08-27
# generated-by: Me
# id: 1
#%ENDS
#%BODY
....
#%ENDS
#%META
# date: 2022-08-27
# generated-by: Another Me
# id: 2
#%ENDS
#%BODY
....
#%ENDS';
if (preg_match_all($re, $str, $matches)) {
$result = array_map(function ($s) {
return preg_replace("/^#\h*/m", "", trim($s));
}, $matches[1]);
var_export($result);
}
- Output for 7.4.0 - 7.4.33, 8.0.1 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.7
- array (
0 => 'date: 2022-08-27
generated-by: Me
id: 1',
1 => 'date: 2022-08-27
generated-by: Another Me
id: 2',
)
preferences:
114.48 ms | 402 KiB | 122 Q