Exercise 3 solution import re s = "a [one] b [two words] c [] d" print(re.findall(r"(?<=\[).*?(?=\])", s)) # ['one', 'two words', ''] print(re.findall(r"(?<=\[).+?(?=\])", s)) # ['one', 'two words'] (All lines were run and printed exactly what is shown.) Explanation: (?<=\[) requires an opening bracket just before the match and (?=\]) a closing bracket just after, and neither is part of the result. The lazy .*? stops at the first closing bracket; because * allows zero characters, the empty brackets produce an empty string. Changing * to + demands at least one character, so empty brackets are ignored.