Question: Problem 1 (10 points): highlight (pattern, string) Write a Python function named highlight (), which takes a raw string specifying a regex pattern as the

 Problem 1 (10 points): highlight (pattern, string) Write a Python function

Problem 1 (10 points): highlight (pattern, string) Write a Python function named highlight (), which takes a raw string specifying a regex pattern as the first argument, called pattern, and a string as the second argument, called string. The function will compile pattern and apply the compiled pattern to string. If a match is found, then the function will return a string in which the matched substring of string is enclosed in angle brackets. If no match is found, the function should return None. For example, suppose that: pattern = r'[a-zA-Z]\d' string "ShepardN7" returns: "Shepard" Test Cases: pattern = r' \bbook\B' strings ["bookstore", "booking", "textbooks", "'returned books'", "audiobook"]

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!