import re


def ExtractRegex(pat, str):
  """Return the first captured string of the regex or None if there was no match."""
  m = re.search(pat, str, re.DOTALL)
  if not m: return None
  try:
    return m.group(1)
  except IndexError:
    return None