1. Write a Python regex pattern that matches a valid email address, assuming that an email address consists of a username, followed by the "@" symbol, followed by a domain name, which in turn consists of one or more subdomains separated by dots, and ending with a top-level domain (e.g., .com, .org, .edu, etc.). 2. Using the re.findall() function in Python, write a Python code snippet that takes the text string and the regex pattern from Q4 and returns a list of all the email addresses found in the string. 3. Suppose you want to modify the regex pattern from Q4 to also match email addresses that contain hyphens ("-") in the username and/or domain name. What changes would you make to the pattern, and why? 4. Using the modified regex pattern from Q6, write a Python code snippet that takes the text string and the modified regex pattern, and returns a list of all the email addresses found in the string. Note: You can assume that the text string contains valid email addresses separated by whitespace or punctuation marks. You can also assume that the email addresses do not contain any whitespace or punctuation marks inside the username or domain name.
1. Write a Python regex pattern that matches a valid email address, assuming that an email address consists of a username, followed by the "@" symbol, followed by a domain name, which in turn consists of one or more subdomains separated by dots, and ending with a top-level domain (e.g., .com, .org, .edu, etc.).
2. Using the re.findall() function in Python, write a Python code snippet that takes the text string and the regex pattern from Q4 and returns a list of all the email addresses found in the string.
3. Suppose you want to modify the regex pattern from Q4 to also match email addresses that contain hyphens ("-") in the username and/or domain name. What changes would you make to the pattern, and why?
4. Using the modified regex pattern from Q6, write a Python code snippet that takes the text string and the modified regex pattern, and returns a list of all the email addresses found in the string.
Note: You can assume that the text string contains valid email addresses separated by whitespace or punctuation marks. You can also assume that the email addresses do not contain any whitespace or punctuation marks inside the username or domain name.
Trending now
This is a popular solution!
Step by step
Solved in 3 steps