Regex match final square brackets of string