From 71b3ab2bf6b39138587927bb726ef02fbc6995a6 Mon Sep 17 00:00:00 2001 From: float-trip Date: Mon, 10 Jul 2023 00:57:07 +0000 Subject: [PATCH] Fix remove_notifications() for strings with multiple occurrences. --- utils.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/utils.py b/utils.py index 685185f..7e17610 100644 --- a/utils.py +++ b/utils.py @@ -44,10 +44,13 @@ def remove_notifications(text): "soren", ] + def replace(match): + # Insert after the first character of the matched string. + user = match.group() + return f"{user[:1]}{user[1:]}" + for user in notified_users: - match = re.search(user, text, re.IGNORECASE) - if match: - text = f"{text[:match.start() + 1]}{text[match.start() + 1:]}" + text = re.sub(user, replace, text, flags=re.IGNORECASE) return text