I have an html table with content like this in multiple rows
<td>
Bob Marley (bmarley@whatever.com)
</td>
I'm trying to find and replace this content with just the first part of the email address, and strip the white space.
<td>
bmarley
</td>
This is the current code, that successfully matches on the username portion. I'm not sure how to replace the content between the tags.
name_regex = re.compile('(?<=())[a-zA-Z]+(?=@)')
soup = bs(open(page_source), 'lxml')
for row in soup.select(table_name)[1:]:
name = re.search(name_regex,row.select_one('td:nth-of-type(2)').text.strip()).group()
print(name)