Here's an implementation of the in_parentheses function in Python:
The Code
import re
def in_parentheses(a_string):
result = re.search(r'\((.*?)\)', a_string)
return result.group(1) if result else ""
# Test cases
print(in_parentheses("This is a sentence (words!)."))
print(in_parentheses("No parentheses here!"))
print(in_parentheses("David tends to use parentheses a lot (as he is doing right now). It tends to be quite annoying."))
print(in_parentheses("Open ( only"))
print(in_parentheses("Closed ) only"))
print(in_parentheses("Closed ) before ( open"))
print(in_parentheses("That's a lot of test cases(!)"))
This function in_parentheses uses regular expressions to find text enclosed within parentheses in a given string. It returns the content within the parentheses or an empty string if no text appears in parentheses.