code: def char_groups(self, t, i):
          
  
          current = []
          pos = i.index - 1
          found = 0
          sub_first = None
          escaped = False
          first = None
  
          try:
              while True:
                  if not escaped and t == "\\":
                      escaped = True
                  elif escaped:
                      escaped = False
                      current.extend(self.reference(t, i, True))
                  elif t == "[" and not found:
                      found += 1
                      first = pos
                      current.append(t)
                  elif t == "[" and found and self.version == _regex.V1:
                      # Start of sub char set found
                      posix = None if self.is_bytes else self.get_posix(i)
                      if posix:
                          current.append(posix)
                          pos = i.index - 2
                      else:
                          found += 1
                          sub_first = pos
                          current.append(t)
                  elif t == "[":
                      posix = None if self.is_bytes else self.get_posix(i)
                      if posix:
                          current.append(posix)
                          pos = i.index - 2
                      else:
                          current.append(t)
                  elif t == "^" and found == 1 and (pos == first + 1):
                      # Found ^ at start of first char set; adjust 1st char position
                      current.append(t)
                      first = pos
                  elif self.version == _regex.V1 and t == "^" and found > 1 and (pos == sub_first + 1):
                      # Found ^ at start of sub char set; adjust 1st char sub position
                      current.append(t)
                      sub_first = pos
                  elif t == "]" and found == 1 and (pos != first + 1):
                      # First char set closed; log range
                      current.append(t)
                      found = 0
                      break
                  elif self.version == _regex.V1 and t == "]" and found > 1 and (pos != sub_first + 1):
                      # Sub char set closed; decrement depth counter
                      found -= 1
                      current.append(t)
                  else:
                      current.append(t)
                  pos += 1
                  t = next(i)
          except StopIteration:
              pass
  
          if escaped:
              current.append(t)
          return current
docs: Handle character groups.