在PHP中使用正则表达式来查找尚未包含在具有特定类的div中的{%shortcode%}?

I use shortcodes in my HTML content that is treated by PHP. A shortcode can be {%sometag%}. It's always wrapped in {% and %}

I have unto now wrapped these each time I load a page by using:

$SOME['content'] = preg_replace('/{%(.*?)%}/is', 
"<div class=\"portlet \\1adm \" data-type=\"app\">{%\\1%}</div>", 
$SOME['content']);

This works well, and outputs the HTML I want. BUT it wrapps {%sometag%} every time that page is loaded. So I get a wrapper inside a wrapper inside a wrapper etc.

How can I make the regex such that is only chooses /{%(.*?)%}/is but NOT when the shorttag is wrapped in a <div class="app" > ?

(And the class="" can hold many classes?

In other words:

The regex shall choose {%sometag%}

but not when inside a div like this: <div class"portlet app someclass">{%sometag%}</div>

I'm stuck here, and really appreciate some help.

EDIT: Have tried this as suggested in a comment (thank you).

$SOME['content'] = preg_replace('~<div\s+class="portlet[^"<]*"[^<]*>{%.*?%}</div>(*SKIP)(*FA‌​IL)|{%(.*?)%}~is', 
"<div class=\"portlet \\1adm \" data-type=\"app\">{%\\1%}</div>", 
$SOME['content']);

This broke the PHP (blank page).