Greetings
There are many regex templates and one line. Seeking a reasonable way to determine which template matches a string.
At the moment, I'm running a string through the loop from the templates and checking if it matches the pattern.
import re patterns = [ (re.compile("^/upload/test/$"), "upload"), (re.compile("^/download/test/$"), "download"), (re.compile("^/test/$"), "test")] string = "/test/" for pattern in patterns: if pattern[0].match(string): print pattern[1]
Is there a better way?