def AdvSearch(document, search, bs=3):
 searchre = re.compile(search)
 matches = []
 searchels = []
 for element in document.getiterator():
  if (element.tag == ('{%s}t' % nsprefixes['w'])):
   if element.text:
    searchels.append(element)
    if (len(searchels) > bs):
     searchels.pop(0)
    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
       match = searchre.search(txtsearch)
       if match:
        matches.append(match.group())
        found = True
 return set(matches)

def AdvSearch ( document , search , bs = 3 ) : searchre = re . compile ( search ) matches = [ ] searchels = [ ] for element in document . getiterator ( ) : if ( element . tag == ( '{%s}t' % nsprefixes [ 'w' ] ) ) : if element . text : searchels . append ( element ) if ( len ( searchels ) > bs ) : searchels . pop ( 0 ) 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 match = searchre . search ( txtsearch ) if match : matches . append ( match . group ( ) ) found = True return set ( matches )
return set of all regex matches this is an advanced version of python-docx .