docs: def AdvSearch(document, search, bs=3):
      '''Return set of all regex matches
  
      This is an advanced version of python-docx.search() that takes into
      account blocks of <bs> elements at a time.
  
      What it does:
      It searches the entire document body for text blocks.
      Since the text to search could be spawned across multiple text blocks,
      we need to adopt some sort of algorithm to handle this situation.
      The smaller matching group of blocks (up to bs) is then adopted.
      If the matching group has more than one block, blocks other than first
      are cleared and all the replacement text is put on first block.
  
      Examples:
      original text blocks : [ 'Hel', 'lo,', ' world!' ]
      search : 'Hello,'
      output blocks : [ 'Hello,' ]
  
      original text blocks : [ 'Hel', 'lo', ' __', 'name', '__!' ]
      search : '(__[a-z]+__)'
      output blocks : [ '__name__' ]
  
      @param instance  document: The original document
      @param str       search: The text to search for (regexp)
                            append, or a list of etree elements
      @param int       bs: See above
  
      @return set      All occurences of search string
  
      '''
  
      # Compile the search regexp
      searchre = re.compile(search)
  
      matches = []
  
      # Will match against searchels. Searchels is a list that contains last
      # n text elements found in the document. 1 < n < bs
      searchels = []
  
      for element in document.iter():
          if element.tag == '{%s}t' % nsprefixes['w']:  # t (text) elements
              if element.text:
                  # Add this element to searchels
                  searchels.append(element)
                  if len(searchels) > bs:
                      # Is searchels is too long, remove first elements
                      searchels.pop(0)
  
                  # Search all combinations, of searchels, starting from
                  # smaller up to bigger ones
                  # l = search lenght
                  # s = search start
                  # e = element IDs to merge
                  found = False
                  for l in range(1, len(searchels)+1):
                      if found:
                          break
                      for s in range(len(searchels)):
                          if found:
                              break
                          if s+l <= len(searchels):
                              e = range(s, s+l)
                              txtsearch = ''
                              for k in e:
                                  txtsearch += searchels[k].text
  
                              # Searcs for the text in the whole txtsearch
                              match = searchre.search(txtsearch)
                              if match:
                                  matches.append(match.group())
                                  found = True
      return set(matches)