(document, search, replace)
return newdocument
Replace all occurences of string with a different string, return updated document
Replace all occurences of string with a different string, return updated document
Replace all occurences of string with a different string return updated document
def replace(document, search, replace):
    '''Replace all occurences of string with a different string, return updated document'''
    newdocument = document
    searchre = re.compile(search)
    for element in newdocument.iter():
        if element.tag == '{%s}t' % nsprefixes['w']:  # t (text) elements
            if element.text:
                if searchre.search(element.text):
                    element.text = re.sub(search, replace, element.text)
    return newdocument
def replace ( document , search , replace ) : newdocument = document searchre = re . compile ( search ) for element in newdocument . iter ( ) : if element . tag == '{%s}t' % nsprefixes [ 'w' ] : # t (text) elements if element . text : if searchre . search ( element . text ) : element . text = re . sub ( search , replace , element . text ) return newdocument