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


in reply to regex for [ but not \[

Look ahead and look behind assertions are perfect for this sort of thing. In this case, negative assertions can make sure that the extra pattern you specify (i.e. the backslash) doesn't occur:

m/(?<!\\)\[.*?\](?!\\)/g should do what you want.

Update: jeffa pointed out my .?* should in fact be a .*?

elbieelbieelbie