function regexForFormat (format) {
  let escaped = `^${escapeRegExp(format)}$`
  const formats = {
    MM: '(0[1-9]|1[012])',
    M: '([1-9]|1[012])',
    DD: '([012][0-9]|3[01])',
    D: '([012]?[0-9]|3[01])',
    YYYY: '\\d{4}',
    YY: '\\d{2}'
  }
  return new RegExp(Object.keys(formats).reduce((regex, format) => {
    return regex.replace(format, formats[format])
  }, escaped))
}
Given a string format (date) return a regex to match against.
@param {string} format