import bs4
import re
soup = bs4.BeautifulSoup('Snug as a bug in a rug')
print(soup)
for text in soup.findAll(text=True):
    if re.search('ug\\b', text):
        new_html = '<p>' + re.sub('(\\w*)ug\\b', '<b>\\1ook</b>', text
            ) + '</p>'
new_soup = bs4.BeautifulSoup(new_html)
text.parent.replace_with(new_soup.p)
print(soup)
обтекание подразделов текста тегами в BeautifulSoup