I would like to use preg_match_all() to extract the content between [[ and ]], but ignoring [[[ and ]]], so for example this text:
$text = <<<TEXT
Some text going here
[[ 1. this is a text ]]
another text but multiple lines
[[ 2. this
is a
text ]]
This should be ignored, haveing 3 on the left
[[[ 3. this is a text ]]
This should be ignored, haveing 3 on the right
[[ 4. this is a text ]]]
This should be ignored, haveing 3 both on the left and right
[[[ 5. this is a text ]]]
This is the final sentence.
[[ 6. this is a text ]]
TEXT;
if (preg_match_all("(?!<\[)(\[\[.*?\]\])(?!\[)", $text, $tags, PREG_PATTERN_ORDER)) {
$tags = $tags[0];
}
echo '<pre>';
print_r(tags);
echo '</pre>';
So only selecting 1., 2., and 6. But the regex I've tried above is selecting everything except the 2., not working as expected.