Refactor how $format is parsed to RegEx