+def search(needle, haystack):
+ # Search for needle in haystack, first escaping needle for regex, then
+ # replacing %s, %d, etc. with regex wildcards, so the variable messages
+ # within the dungeon definition will actually match
+ needle = re.escape(needle) \
+ .replace("\%S", ".*") \
+ .replace("\%s", ".*") \
+ .replace("\%d", ".*") \
+ .replace("\%V", ".*")
+
+ return re.search(needle, haystack)
+