This is somewhat similar to StringUtils::FindEndBracket, with additional escaping by the looks?