code: def _regex_from_encoded_pattern(s):
      
      if s.startswith('/') and s.rfind('/') != 0:
          # Parse it: /PATTERN/FLAGS
          idx = s.rfind('/')
          pattern, flags_str = s[1:idx], s[idx+1:]
          flag_from_char = {
              "i": re.IGNORECASE,
              "l": re.LOCALE,
              "s": re.DOTALL,
              "m": re.MULTILINE,
              "u": re.UNICODE,
          }
          flags = 0
          for char in flags_str:
              try:
                  flags |= flag_from_char[char]
              except KeyError:
                  raise ValueError("unsupported regex flag: '%s' in '%s' "
                                   "(must be one of '%s')"
                                   % (char, s, ''.join(list(flag_from_char.keys()))))
          return re.compile(s[1:idx], flags)
      else: # not an encoded regex
          return re.compile(re.escape(s))
docs: foo'    -> re.compile(re.escape('foo'))
         '/foo/'  -> re.compile('foo')
         '/foo/i' -> re.compile('foo', re.I)