fork download
  1. <?php
  2.  
  3. $test_string = <<<TEST
  4. [startA]
  5. this is the first group
  6.  [startB]
  7.  blabla
  8. [end]
  9. [end]
  10. [startA]
  11. this is the second group
  12.  [startB]
  13.  blabla
  14. [end]
  15. [end]
  16. [startA]
  17. this is the second group
  18.  [startB]
  19.  blabla
  20. [end]
  21. [end]
  22. TEST;
  23. preg_match_all('#\[startA](.+?)\[end]\s*(?=\[startA]|$)#s', $test_string, $matches);
  24. var_dump($matches[1]);
Success #stdin #stdout 0.02s 13112KB
stdin
Standard input is empty
stdout
array(3) {
  [0]=>
  string(49) "
this is the first group
 [startB]
 blabla
[end]
"
  [1]=>
  string(50) "
this is the second group
 [startB]
 blabla
[end]
"
  [2]=>
  string(50) "
this is the second group
 [startB]
 blabla
[end]
"
}