I've got a list of exact patterns that I want to search in a given string. Currently I've got a real bad solution for such a problem.
pat1 = re.compile('foo.tralingString')
mat1 = pat1.match(mystring)
pat2 = re.compile('bar.trailingString')
mat2 = pat2.match(mystring)
if mat1 or mat2:
# Do whatever
pat = re.compile('[foo|bar].tralingString')
match = pat.match(mystring) # Doesn't work
The only condition is that I've got a list of strings which are to be matched exactly. Whats the best possible solution in Python.
EDIT: The search patterns have some trailing patterns common.
See Question&Answers more detail:os