def _regex_from_encoded_pattern(s):
if s.startswith('<STR_LIT:/>') and s.rfind('<STR_LIT:/>') != <NUM_LIT:0>:<EOL><INDENT>idx = s.rfind('<STR_LIT:/>')<EOL>pattern, flags_str = s[<NUM_LIT:1>:idx], s[idx+<NUM_LIT:1>:]<EOL>flag_from_char = {<EOL>"<STR_LIT:i>": re.IGNORECASE,<EOL>"<STR_LIT:l>": re.LOCALE,<EOL>"<STR_LIT:s>": re.DOTALL,<EOL>"<STR_LIT:m>": re.MULTILINE,<EOL>"<STR_LIT:u>": re.UNICODE,<EOL>}<EOL>flags = <NUM_LIT:0><EOL>for char in flags_str:<EOL><INDENT>try:<EOL><INDENT>flags |= flag_from_char[char]<EOL><DEDENT>except KeyError:<EOL><INDENT>raise ValueError("<STR_LIT>"<EOL>"<STR_LIT>"<EOL>% (char, s, '<STR_LIT>'.join(list(flag_from_char.keys()))))<EOL><DEDENT><DEDENT>return re.compile(s[<NUM_LIT:1>:idx], flags)<EOL><DEDENT>else: <EOL><INDENT>return re.compile(re.escape(s))<EOL><DEDENT>
foo'    -> re.compile(re.escape('foo'))
       '/foo/'  -> re.compile('foo')
       '/foo/i' -> re.compile('foo', re.I)