Is there any way to have this:
[one[two]][three]
And extract this with a regex?
Array (
[0] => one[two]
[1] => two
[2] => three
Is there any way to have this:
[one[two]][three]
And extract this with a regex?
Array (
[0] => one[two]
[1] => two
[2] => three
For PHP you can use recursion in regular expressions that nearly gives you what you want:
$s = 'abc [one[two]][three] def';
$matches = array();
preg_match_all('/\[(?:[^][]|(?R))*\]/', $s, $matches);
print_r($matches);
Result:
Array
(
[0] => Array
(
[0] => [one[two]]
[1] => [three]
)
)
For something more advanced than this, it's probably best not to use regular expressions.