regexp php,我需要替换模板的所有单词

I need to replace all the words of the template, but these words enclosed in {} and []. Please help

$content = '<div class="header header">{header} {header2} [header][/header]</div>';
$content = preg_replace("/(\s|\"|\')(^$)header(^$)(\s|\"|\')/is",'new_class',$content);

OUTPUT should be the following: <div class="new_class new_class">{header} {header2} [header][/header]</div>

This should work

$content = '<div class="header header">{header} {header2} [header][/header]</div>';
$content = preg_replace("/([\\s\"'])header(?=[\\s\"'])/is",'$1new_class',$content);

This replaces all "header" surrounded by either "' or white space.

$result = preg_replace('/header(?![^{}[\]]*[\]}])/', 'new_class', $subject);

replaces header with new_class only if the next following bracket or brace is not a closing bracket or brace.