You're doing a few things wrong, including not turning on error reporting because you have mismatched ()
's and an /
that needs escaping.
The first problem is that .* is greedy. So in your string it will match: test somerandomURL><b>apple</b>
Usually the solution to that is to make it lazy with .*?
but because of the negative lookahead, laziness will still make it match up to a further >
when apple is found.
The solution is a negated character class. [^>]*
will match any char except >
/test([^>]*)>(?!<b>apple<\/b>)(.*)/i