import re foo = 42 re.compile(rf'.*{foo}.*') #