0% found this document useful (0 votes)
20 views

7 Python Regex Search Function Coding Exercise

The document discusses a Python regex exercise to search for and remove the word 'take_out' from an email string using regex functions. The task is to complete the regex_processor function by choosing the correct search function (search or match) and using m.start() and m.end() to slice the string for printing.

Uploaded by

ArvindSharma
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views

7 Python Regex Search Function Coding Exercise

The document discusses a Python regex exercise to search for and remove the word 'take_out' from an email string using regex functions. The task is to complete the regex_processor function by choosing the correct search function (search or match) and using m.start() and m.end() to slice the string for printing.

Uploaded by

ArvindSharma
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Python Regex search ( ) function - Coding exercise

Test your Python Regex search() and group() function skills.

WE'LL COVER THE FOLLOWING

• The Search Function Exercise

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" ?

#!/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!!")

Regex processor function

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() ).
Show Hint

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy