def regexHasCaptureWitness(regex):
  """Returns True if regex has a Capture Witness among its witnesses

  Capture witness: An input where
    - some pair of languages agrees on a match and the matched substring, but
    - disagrees on the capture group contents
  """
  # Check if any of the SDWs disagreed about the capture groups for a match
  for sdw in regex.semanticDifferenceWitnesses:
    # Get the substrings matched
    uniqueMatchingSubstrings = set([
      mr.matchContents.matchedString
      for mr in sdw.matchResultToLangs
      if mr.matched
    ])
    #libLF.log("  uniqueMatchingSubstrings: {}".format(uniqueMatchingSubstrings))

    # For each substring, see if multiple capture groups were found
    for matchedString in uniqueMatchingSubstrings:
      distinctCaptureGroupsForString = [
        mr.matchContents.captureGroups
        for mr in sdw.matchResultToLangs
        if mr.matchContents.matchedString == matchedString
      ]
      if len(distinctCaptureGroupsForString) > 1:
        #libLF.log("  {} distinct capture groups for matchedString {}" \
        #  .format(len(distinctCaptureGroupsForString), matchedString))
        #libLF.log("Capture witness: {}".format(sdw.toNDJSON()))
        return True
  return False