diff --git a/notifications_utils/logging.py b/notifications_utils/logging.py index f2ed80e71..99c349cdd 100644 --- a/notifications_utils/logging.py +++ b/notifications_utils/logging.py @@ -19,6 +19,7 @@ logger = logging.getLogger(__name__) _phone_regex = re.compile("(?:\\+ *)?\\d[\\d\\- ]{7,}\\d") +_email_regex = re.compile(r"[\w\.-]+@[\w\.-]+") # ['alice@google.com', 'bob@abc.com'] def _scrub(msg: Any) -> Any: @@ -30,9 +31,7 @@ def _scrub(msg: Any) -> Any: for phone in phones: msg = msg.replace(phone, "1XXXXXXXXXX") - emails = re.findall( - r"[\w\.-]+@[\w\.-]+", msg - ) # ['alice@google.com', 'bob@abc.com'] + emails = _email_regex.findall(msg) for email in emails: # do something with each found email string masked_email = "XXXXX@XXXXXXX"