javascript - Don't Grab Word With Regex If It Has Tags Around It JS -


i having trouble regex, , tbh not sure if possible.

ok if text has [code] tags around it, text inside not parsed. let me show mean:

[b]this text appear bold[/b] [code] [b]this text not appear bold, bold tags still shown[/b] [/code] 

so trying check , see if text has [code] tags around it. have tried regex:

/((?!\[code\])\[b\](.*)\[\/b\](?!\[\/code\]))/gi 

so thought (?!\[code\]) not display text if had around it, still not working. if text has [code] around it, text inside higlighted, [code] tag not be. how go showing bold if not have code tags around it?

to avoid way match first , capture it. replace text enclosed between [b] tags except when theses tags between [code] tags, can write:

txt=txt.replace(/(\[code\][\s\s]*?\[\/code\])|\[b\]([\s\s]*?)\[\/b\]/g,      function (m, g1, g2) { return g1 ? g1 : '<b>' + g2 + '</b>';  }); 

so when group 1 exists returned without change. when not defined replacement string returned.


Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -