Search⌘ K
AI Features

Python Regex search ( ) function - Coding exercise

Explore how to use the Python regex search function through a coding exercise that involves modifying an email string. Learn to identify and apply the correct regex methods to locate and replace parts of a string, enhancing your understanding of Python's re module functions.

We'll cover the following...

The Search Function Exercise

Let’s assume that we have a string variable called email, where email = "hello@scitake_outentificprogramming.io" passed to a function called regex_processor() in the following code.

Can you remove the word "take_out" and print the email address "hello@scientificprogramming.io"?

Python 3.5
#!/usr/bin/python
import re
def regex_processor(email):
#email = "hello@scitake_outentificprogramming.io ";
# replace 'match ()' with the appropriate function
m = re.match("take_out", email)
# replace '0' with the 'm.start()' and 'm.end()' at the appropriate indices?
if m:
print (email[:0] + email[0:])
else:
print ("No match!!")

Your task is to replace the '?' on the line 8 with the correct function name (match or search ?) and replace he ? marks on the line 12 with correct match object function calls (hint: m.end() and m.start()).