Python:
import re
def make_extractor(pattern_str):
# Escape the whole string so regex metacharacters don’t break it
escaped = re.escape(pattern_str)
# Replace the escaped 'fudge' with a capture group
regex_str = escaped.replace(r"fudge", r"(.*)")
return re.compile(regex_str)
Python:
s = "my favorite food is fudge today"
regex = make_extractor(s)
m = regex.fullmatch("my favorite food is chocolate today")
print(m.group(1)) # chocolate