improved RegEx
Added support for square brackets