Command Palette

Search for a command to run...

Hectal
Phase 10: Security and Privacy (Defensive)
RAG and Vector Search · Exercise 2 of 6 PreviousNext
Beginner

Redact emails and phone numbers

Write redact(text) that replaces every email address with [EMAIL] and every phone number of the form +1 555 010 4477 (a plus, one digit, then groups of 3, 3 and 4 digits separated by spaces) with [PHONE], and returns the new text.

Use the re module with these two patterns: [A-Za-z0-9._-]+@[A-Za-z0-9-]+[.][A-Za-z]{2,} for emails and [+][0-9] [0-9]{3} [0-9]{3} [0-9]{4} for phones. The values in the checks are invented.

What Check tests

  1. Replaces an email and a phone number
  2. Replaces every email, not just the first
  3. Leaves text without personal data unchanged
  4. Handles a dot before the at sign
  5. Does not redact an ordinary number

Stuck? One hint at a time

The solution unlocks after your first Check. Try first: that is where the learning happens.

main.py
Sign in to run your code.

Output

Press Run to see what your program prints.