Forum Moderators: coopster
It needs to ignore brackets within brackets. So it won't return (11) but will return (10(11)12).
$preg = '/\((?:[^()]+¦(?R))*\)/';
$str = '123(456)(789)(10(11)12)';
if(preg_match_all($preg, $str, $matches)) {
$matches = $matches[0];
} else {
$matches = array();
}
echo '<pre>'.print_r($matches,true).'</pre>';
This returns:
Array
(
[0] => (456)
[1] => (789)
[2] => (10(11)12)
)
Which is perfect. However, how can I get this working for a string with square brackets instead e.g:
$str = '123[456][789][10[11]12]';