I want to use regular expression to print all the text fragments in a list found in another text. Both texts are prompted by the user and the names (egg and egg_carton are just names, it's not about eggs). The following code prints an empty list. I think the problem is the re.compile part of the code, but I don't know how to fix this problem. I would like the code modified in it's form, not a completely other method of solving this problem. Appreciate it.
import re
egg= input()
egg_carton = input()
text_fragment = re.compile(r'(egg)')
find_all = text_fragment.findall(egg_carton)
print(find_all)
eggwith that sample input)?egginegg_carton, then you need to use:text_fragment = re.compile(r'({0})'.format(egg)). The.format(egg)converts{0}to contain the value ofegg.egg = "up", thenre.compile(r'({0})').format(egg))is equivalent tore.compile(r'(up)').formatin the Python specifications for your version.