import re


def MatchPattern(file_path, pattern):
  """Looks for matching specified pattern in the file line by line.

  Args:
    file_path: file path.
    pattern: pattern for matching.
  Returns:
    the match or None.
  """
  try:
    with open(file_path, "r") as f:
      prog = re.compile(pattern)
      for line in f:
        match = prog.match(line)
        if match:
          return match
  except IOError:
    pass
  except Exception:
    pass

  return None