Skip to content

Commit

Permalink
Compiling email regex
Browse files Browse the repository at this point in the history
Signed-off-by: Cliff Hill <[email protected]>
  • Loading branch information
xlorepdarkhelm committed Oct 30, 2024
1 parent 452ab7e commit 278541f
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions notifications_utils/logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
logger = logging.getLogger(__name__)

_phone_regex = re.compile("(?:\\+ *)?\\d[\\d\\- ]{7,}\\d")
_email_regex = re.compile(r"[\w\.-]+@[\w\.-]+") # ['[email protected]', '[email protected]']


def _scrub(msg: Any) -> Any:
Expand All @@ -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
) # ['[email protected]', '[email protected]']
emails = _email_regex.findall(msg)
for email in emails:
# do something with each found email string
masked_email = "XXXXX@XXXXXXX"
Expand Down

0 comments on commit 278541f

Please sign in to comment.