python regex to match whole line with a particular regex pattern
问题 I have a file with a list of regex patterns and string containing '\n's' i.e a string with seperate lines ... I need a generic regex that can match the whole line with patterns in the regex file such that i can do something like re.compile(r'generic_regex%s') %regex_pattern from file and it automatically matches the whole line much like grep. Any ideas?? 回答1: Something like: >>> re.findall(r"(^.*?%s.*?$)" %expression, text, re.MULTILINE) ? 回答2: Adjust for any boundaries etc... import re