in reply to Parsing using Regex and Lookahead

Just a small hint: when you have something of the form ^\[ .*? \] the regex engine can backtrack over the ] char, which might not be what you want. For example it can match the whole string of [a][b] if something after that part of the regex causes backtracking.

Instead you can use this regex: ^\[ [^\]]* \]

Which always matches an opening bracket, other characters and then the closing bracket, so in the example above it will never match more than the [a]

(whitespaces added for clarity, you need the /x modifier if you want to keep them).