<?php
//I want the 'delimX' to be included as well:
$str = "It seems entirely 1 (b natural b) to us that there are teams of scientists in universities and other institutions around the world, attempting to 2 (b discover b) the way the world works. However, it hasn't always been that 3 (b way b) . Although the scientific method is now four or five hundred years old, the ancient Greeks, for example, believed that they could work out the 4 (b causes b) of natural events just by the power of thought.";
$result = preg_split ('~(\(b.*?b\))~',$str ,-1, PREG_SPLIT_DELIM_CAPTURE);
var_dump($result);
array(9) {
[0]=>
string(20) "It seems entirely 1 "
[1]=>
string(13) "(b natural b)"
[2]=>
string(115) " to us that there are teams of scientists in universities and other institutions around the world, attempting to 2 "
[3]=>
string(14) "(b discover b)"
[4]=>
string(64) " the way the world works. However, it hasn't always been that 3 "
[5]=>
string(9) "(b way b)"
[6]=>
string(146) " . Although the scientific method is now four or five hundred years old, the ancient Greeks, for example, believed that they could work out the 4 "
[7]=>
string(12) "(b causes b)"
[8]=>
string(48) " of natural events just by the power of thought."
}
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(9) {
[0]=>
string(20) "It seems entirely 1 "
[1]=>
string(13) "(b natural b)"
[2]=>
string(115) " to us that there are teams of scientists in universities and other institutions around the world, attempting to 2 "
[3]=>
string(14) "(b discover b)"
[4]=>
string(64) " the way the world works. However, it hasn't always been that 3 "
[5]=>
string(9) "(b way b)"
[6]=>
string(146) " . Although the scientific method is now four or five hundred years old, the ancient Greeks, for example, believed that they could work out the 4 "
[7]=>
string(12) "(b causes b)"
[8]=>
string(48) " of natural events just by the power of thought."
}