def extract_regex_captures(captures, regex, string):
  """Fills `captures` with the matches of `regex` in `string`.

  This is a convenience function that populates a list with all the matching
  substrings of the given regex in the given string and returns if there were
  any matches. This is useful for when there are cascading if/elif statements
  and you want to find the first regex that matches.

  Args:
    captures: A list to populate with matches, if any.
    regex: The regex to match against.
    string: The string to run the regex over.
  Returns:
    Whether or not there were any matches.
  """
  del captures[:]
  matches = regex.search(string)
  if matches:
    captures.extend(list(matches.groups()))
  return matches is not None