`format.replace(/[MD]/g, 'x')` could do the replacement in the format.