Use /Z instead of $ to anchor the [] regexp in multipart.