import re


def match(regex, line):
  """Match *entire* line to regex converting all spaces into '\s+' and allowing trailing spaces."""
  regex = regex.replace(" ", r"\s+")
  regex += r"\s*\Z"
  return re.match(regex, line)