To view the full archive of past projects, visit the Daily Python Projects homepage at https://dailypythonprojects.substack.com.
Subscribe below to receive a new Python project every day by email:
Project Brief
Your task for this project is to extract the email addresses and phone numbers from a piece of text.
Project Instructions
Download this text file. The file contains the following text:
"Contact us at support@example.com or marketing@example.com. For urgent queries, call us at (123) 456-7890 or 123.456.7890. Alternatively, reach out on 123-456-7890.”Write a script that extracts all the emails and all the phone numbers from that text file and prints them out in the terminal.
Expected Output
The following should be printed out in the terminal:
['support@example.com', 'marketing@example.com']
['123.456.7890', '123-456-7890']
Environment Setup Instructions
You can use the re standard library for this. You don’t need to install anything.
Run the app with python main.py.
Resources
You can learn how to extract text using the Python standard library on the Python official docs:
https://docs.python.org/3/library/re.html
The provided solution and output do not include the phone number with parentheses. I used the following phone pattern instead:
r'(\({,1}\d{3}\){,1}[\s.-]\d{3}[\s.-]\d{4})'