tag as the pseudo HTML is creating havoc on square brackets. Basically I want the most outer [ some chars] or { some chars } but not [] or {} 2 other examples: 1) a[] = [ this is a test { test2 } ] Should only match [ this is a test { test2 } ] 2) a[] = [ this is a [ test ] { test2 } ] Should return [ this is a [ test ] { test2 } ]