Lab: Redacted
Due: Wednesday, November 18 at 11:59pm (one week after it is assigned) · Worth: 4 points
Regular expressions can help us find contact information in text and hide sensitive numbers before sharing a report. You’ll work with fictional campus-visit tickets that use public admissions contacts from the seven Claremont Colleges. The Social Security and card numbers are made up.
Start
Download and extract the starter ZIP. Open the inner lab-regex folder in VS Code, then initialize and publish your repository as lab-regex. Open lab_regex.py and support_tickets.json. The input separates message, contact, and card fields.
Inspect and redact
Complete the twelve helpers using their docstrings and doctests. Use the regex reading and its reference table for pattern syntax and the re functions. Write patterns as raw strings.
Start with the helpers that find digits and contact details. Then write the ones that validate email addresses and redact sensitive fields. The starter specifies which formats each pattern should recognize.
-
Implement
has_digit,find_numbers, andmask_digits: check for any digit, extract consecutive digit runs as strings, and replace each digit withX. -
Implement
find_phone_numbersandarea_codeusing the formats in their doctests. Implementis_valid_emailto check the whole string, rejecting extra text and a trailing newline. Preserve the order of phone-number matches and keep duplicates. -
Implement
find_urls,find_hashtags, andfind_mentionsusing the formats in their doctests. Preserve match order and duplicates. -
Implement
redact_emails,redact_ssns, andmask_last_four. Replace emails with[REDACTED], SSNs withXXX-XX-XXXX, and all but the last four digits of a sixteen-digit card with stars.
Check and submit
Run:
python -m doctest lab_regex.py
python review_packet.pyYou can run individual report stages with python review_packet.py --stage inspect, index, validate, or redact. In the complete report, the first contact is valid and the second is invalid. The first card becomes ************5678. Check that redaction leaves ordinary message text unchanged.
Commit and sync lab_regex.py. On Gradescope, choose GitHub and submit lab-regex and the branch containing your work. The submission guide explains resubmission.