<?php
$re = '/^\h*\\\\_+\\\\_\R((?:.*\R(?!\h*\\\\_+\\\\_).*)*)/m';
$str = '---
- ID: some random id
\\_______________________________\\_
HELLO
This is an example text.
I AM SECTION 1
\\_______________________________\\_
HELLO
This is an example text.
I AM SECTION 2
\\_______________________________\\_
HELLO
This is an example text.
I AM SECTION 3
\\_______________________________\\_
hello
this is example text here
and i am section 4';
preg_match_all($re, $str, $matches);
print_r($matches[1]);
Array
(
[0] => HELLO
This is an example text.
I AM SECTION 1
[1] => HELLO
This is an example text.
I AM SECTION 2
[2] => HELLO
This is an example text.
I AM SECTION 3
[3] => hello
this is example text here
and i am section 4
)
Output for 8.3.5
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0
Array
(
[0] => HELLO
This is an example text.
I AM SECTION 1
[1] => HELLO
This is an example text.
I AM SECTION 2
[2] => HELLO
This is an example text.
I AM SECTION 3
[3] => hello
this is example text here
and i am section 4
)