docs: def _sequence(self, i):
          """Handle character group."""
  
          result = ['[']
          end_range = 0
          escape_hyphen = -1
          removed = False
          last_posix = False
  
          c = next(i)
          if c in ('!', '^'):
              # Handle negate char
              result.append('^')
              c = next(i)
          if c == '[':
              last_posix = self._handle_posix(i, result, 0)
              if not last_posix:
                  result.append(re.escape(c))
              c = next(i)
          elif c in ('-', ']'):
              result.append(re.escape(c))
              c = next(i)
  
          while c != ']':
              if c == '-':
                  if last_posix:
                      result.append('\\' + c)
                      last_posix = False
                  elif i.index - 1 > escape_hyphen:
                      # Found a range delimiter.
                      # Mark the next two characters as needing to be escaped if hyphens.
                      # The next character would be the end char range (s-e),
                      # and the one after that would be the potential start char range
                      # of a new range (s-es-e), so neither can be legitimate range delimiters.
                      result.append(c)
                      escape_hyphen = i.index + 1
                      end_range = i.index
                  elif end_range and i.index - 1 >= end_range:
                      if self._sequence_range_check(result, '\\' + c):
                          removed = True
                      end_range = 0
                  else:
                      result.append('\\' + c)
                  c = next(i)
                  continue
              last_posix = False
  
              if c == '[':
                  last_posix = self._handle_posix(i, result, end_range)
                  if last_posix:
                      c = next(i)
                      continue
  
              if c == '\\':
                  # Handle escapes
                  subindex = i.index
                  try:
                      value = self._references(i, True)
                  except PathNameException:
                      raise StopIteration
                  except StopIteration:
                      i.rewind(i.index - subindex)
                      value = r'\\'
              elif c == '/':
                  if self.pathname:
                      raise StopIteration
                  value = c
              elif c in SET_OPERATORS:
                  # Escape &, |, and ~ to avoid &&, ||, and ~~
                  value = '\\' + c
              else:
                  # Anything else
                  value = c
  
              if end_range and i.index - 1 >= end_range:
                  if self._sequence_range_check(result, value):
                      removed = True
                  end_range = 0
              else:
                  result.append(value)
  
              c = next(i)
  
          result.append(']')
          # Bad range removed.
          if removed:
              value = "".join(result)
              if value == '[]':
                  # We specified some ranges, but they are all
                  # out of reach.  Create an impossible sequence to match.
                  result = ['[^%s]' % ('\x00-\xff' if self.is_bytes else uniprops.UNICODE_RANGE)]
              elif value == '[^]':
                  # We specified some range, but hey are all
                  # out of reach. Since this is exclusive
                  # that means we can match *anything*.
                  result = ['[%s]' % ('\x00-\xff' if self.is_bytes else uniprops.UNICODE_RANGE)]
              else:
                  result = [value]
  
          if self.pathname or self.after_start:
              return self._restrict_sequence() + ''.join(result)
  
          return ''.join(result)