"Only if it doesn't have a specified string ahead of it" sounds like a forward negative assertion to me....
Matching "foo" only if it's not followed by "bar"... where "foo" and "bar" are regular expressions that match what you want to highlight and what the specified string is respectively ...
foo(?!(.bar)*)
(plus bits on either side for matching the rest of the string depending on context).
E.g., match "if", "else" and "elseif" only if they're not followed by a %...
(if|elseif|else)(?!(.%)*)
That's straight off the top of my head.
But the problem is a lot more complicated than that. What about
if(a==b) % we need to see if b<50% or not
? Both "if"s will be highlighted, because both are followed by %.
You'll find yourself looking towards a full-blown parser; and regular expressions are not as powerful as you'll be wanting.
One idea I showed on this forum in the past might be of use to you; in effect it can be used as a poor man's parse tree, but ultimately you might find yourself wanting to do a proper job of it. Good luck!