I'm using the following regex to find IMG bbcodes and their contents in forum posts:
~\[img(?:=[\'"]?([^,]*?)(?:,[^]\'"]+)?[\'"]?)?]([^\[]+)?\[/img]~i
This works so far, but i need to define exceptions. I must find all IMG bbcodes, which are NOT surrounded by a TT- or CODE bbcode. I'm not trying to parse BBCodes (because this is done by the forum software itself).
So i want the img bbcode from here (which is working, using the regex above):
Hello, this is an example: [img]xxx[/img] - Yay!
but not from there
[tt]this is a test [img]xxx[/img] yolo![/tt]
and not from here
[code=php]<?php
echo '[img=xxx][/img]';[/code]
Any idea, how to achieve this? I'm using PHP (just in case, that a regex-only-solution is not possible).