import re


def regexp_extract(pattern, method=re.match, group=1):
  """Returns the string that matches the specified group in the regex pattern.

  Args:
    pattern: A regular expression to match on with at least one group.
    method: The method to use for matching; normally re.match (the default) or
        re.search.
    group: The group to use for extracting a value; the first group by default.

  Returns:
    A single-argument function that returns the string that matches the
    specified group in the pattern, or None if no match was found or the input
    was empty.
  """

  def regexp_extract_lambda(value):
    if not value:
      return None
    matches = method(pattern, value)
    if not matches:
      return None
    return matches.group(group)

  return regexp_extract_lambda