http://www.perlmonks.org?node_id=1081393


in reply to Re: Regular expressions: Extracting certain text from a line
in thread Regular expressions: Extracting certain text from a line

I used the
tag as the pseudo HTML is creating havoc on square brackets. <code> Basically I want the most outer [ some chars] or { some chars } but no +t [] 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 } ]

I simplified by looking only at square brackets but still no joy.

I thought of something like this:

\[ <- a square bracket .[^\/] <- followed by any character but not an end bracket + <- at least one character
I give up, I will just look for brackets and if it matches empty brackets I filter them out in the code