Is it possible to exclude some elements from parsing when using regular expression and .replace()?

Posted by Fletus Mefitis on Stack Overflow See other posts from Stack Overflow or by Fletus Mefitis
Published on 2012-09-11T14:17:12Z Indexed on 2012/09/11 15:38 UTC
Read the original article Hit count: 125

Filed under:
|
<script language="javascript">
    $("div.post-content , .parsedsig").each(function(){
        if($(this).html().indexOf("[/tabulaScriptum]") != -1) {
             pattern = /\[tabulaScriptum=(.*?)\]([^\[]*)\[\/tabulaScriptum\]/gi
             $(this).html($(this).html().replace(pattern, "<div class='tabulaScriptum'><div class='tabulaNomen'>$1</div><div class='tabulaImpleo'>$2</div></div>")) 
        }
    });
</script>

This script is working perfectly, except for one thing... I need not to replace [tabulaScriptum=][/tabulaScriptum] in certain elements. For example, I don't want to replace those "tags" in element that has class .code-box. Is it possible?

Clarification: element .code-box is located within .post-content.

Clarification #2: this script creates simple division spoiler. .tabulaScriptum is spoier's body, .tabulaNomen is spoiler's name and button which, in turn, reveals(or hides) .tabulaImpleo on click. Reveal\hide script is located in some other place, and I didn't post it here since it doesn't really matter.

Clarification #3: http://jsfiddle.net/PRtsw/1/ fiddle.

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about regex