txt = 'abcd\\sectiondefghi'
pattern = re.compile(re.escape(motif))
txt = 'abcd\\sectiondefghi'
print(pattern.findall(txt))
Convert user input strings to raw string literal to construct regular expression