thank you all for your contributions! I am quite new to all of this, but a way around it was using another Playwright function that allowed to manipulate the HTML string to match the text. So, instead of using :text-matches
I used inner_text()
Please find the code snippet that was modified below:
while names_to_find:
# Get all <tr> elements in the table body
rows = page.locator("table tbody tr")
# Iterate over each row in the table
for i in range(await rows.count()):
# Get the name in lowercase
name_unit = await rows.nth(i).locator('td[data-label="nameunit"]').inner_text()
name_unit_lower = name_unit.strip().lower()