text = """ Pratap
pandey
age
25
student
"""
keyword = "age"
re_compile = re.compile('((.*\n+){2})keyword((.*\n+){2})')
re_result = re.findall(re_compile, text)
I want to write a regex for extracting two lines before keyword and two lines after keyword when keyword is matched, with variable.