Programming on regular expressions.

The Hedge of Protection Hospital, known as the HOP (cue fun music here), recently split its
Admissions department into two sections: A – L and M – Z. Each department searches for data
pertaining to its section and then processes it. For your section, A – L, use regexes to do the
following:

  • In order to share the HOP newsletter and other specific information, read data from a
    copied input file and search it for email addresses in any standard format that begin
    with A – L to identify your patients’ primary contact email; ignore email addresses
    beginning with M – Z.
  • Separately, search for valid telephone numbers, including (xxx) xxx-xxxx and xxx-xxxxxxx.
  • To get some general demographic information, search for patient birthdates (format
    DD/MM/YYYY). Using the year only, select patients who were born prior to the year
    2000; ignore all other ages.
    Name your Python source code file HOP_Regex_YourName.py. Your program will need to:
  1. Create an output header welcoming the user.
  2. Compile three regexes, one each for phone numbers, dates, and email addresses.
    o For the phone number, address phone formats xxx-xxx-xxxx and (xxx) xxx-xxxx.
    The phone regex from the book addresses more than you need. Do not use it;
    create one that addresses these formats only.
    o For the email address, address any standard format which ends with .org or
    .com; ignore all others. Remember to verify that they begin with letters A – L
    and to ignore all others.
    o For the dates, address date format DD/MM/YYYY only. Check that the dates are
    legitimate by verifying that the month is between 1 and 12, inclusive, and that
    the days are between 1 and 31, inclusive; ignore all others.
  3. Use pyperclip to copy data from the clipboard; then process the input against the
    regexes and other data verification. Remember to copy the data to the clipboard before
    running your program – else your output will be empty. Consider placing each regex’s
    output into its own list.
    Use TheHOP_Admissions file provided as your data source (possibly called txt.rtf by
    D2L). Note: I may test the program against different source data.
  4. Sort each list.
  5. Print an informative header, additional helpful information, and each Admissions’ list to
    the screen

Sample Solution