Edit element text using regex?

18 views
Skip to first unread message

Heck Lennon

unread,
Apr 12, 2023, 8:41:45 AM4/12/23
to beautifulsoup
Hello,

I see that BS supports regexes in find/find_all, but does it also support regexes to edit an element's text, as a simpler wayt than this?

===========
#remove header "name=Blah description="
pattern_desc = re.compile('^name=.+? description=(.+)$')
for wpt in soup.find_all('wpt'):
desc = wpt.desc.string
m = pattern_desc.search(desc)
if m:
desc = m.group(1)
print(desc)
===========

Thank you. 
Reply all
Reply to author
Forward
0 new messages