Module 3 challenge: Work with Regular Expressions :Using Python to Interact with the Operating System (Google IT Automation with Python Professional Certificate) Answers 2025
1. Regular expression
✔️ A sequence of characters that forms a search pattern
❌ A method of encrypting data
❌ A function in Python for handling exceptions
❌ A type of data structure in Python
2. re.split() function
✔️ Splits a string into a list of substrings based on a regular expression pattern
❌ Checks for substring
❌ Concatenates strings
❌ Removes occurrences
3. Extract URLs with regex
✔️ pattern = r'https://\S+?\.\w+'
✔️ result = re.findall(pattern, website)
❌ Other methods
4. Split sentences including punctuation
✔️ pattern = r'\S+!? (or r'\S+|\S+?[\.\?!]')
✔️ result = re.findall(pattern, sentence)
❌ Other methods
5. Extract product IDs starting with 1
✔️ pattern = r'1\d{3}-[A-Z]{2}-\d{2}'
✔️ result = re.findall(pattern, report)
❌ Other methods
6. Role of replace_domain()
✔️ To replace the old domain with the new domain in an email address
❌ Iterate over list
❌ Write CSV
❌ Read CSV
7. Initializing old_domain_email_list
✔️ Step 1: Initialized list. Step 2: Used for loop to check each email with contains_domain() regex. Step 3: Appended emails with old domain.
❌ Manual inspection
❌ Using list comprehension
❌ Using regex only
8. Why close() method
✔️ To free up system resources and prevent further reading or writing to the file
❌ Ensure file remains open
❌ Encrypt file
❌ Delete file
9. Key benefit of Python + regex for reports
✔️ To automate repetitive tasks and data analysis
❌ Develop VR
❌ Enhance cybersecurity
❌ Optimize website
10. Purpose of contains_domain() function
✔️ To check if an email address belongs to a specific domain, using regular expressions (regex)
❌ Encrypt emails
❌ Add new domain
❌ Count emails
📌 Summary Table
| Q# | Correct Answer(s) |
|---|---|
| 1 | A sequence of characters that forms a search pattern ✔️ |
| 2 | Splits a string into a list based on regex ✔️ |
| 3 | pattern = r'https://\S+?\.\w+', re.findall ✔️ |
| 4 | pattern = r'\S+!?', re.findall ✔️ |
| 5 | pattern = r'1\d{3}-[A-Z]{2}-\d{2}', re.findall ✔️ |
| 6 | Replace old domain with new domain ✔️ |
| 7 | Initialize list + for loop + contains_domain() ✔️ |
| 8 | Free up system resources ✔️ |
| 9 | Automate repetitive tasks and data analysis ✔️ |
| 10 | Check if email belongs to specific domain using regex ✔️ |