I have the following string from which I'm trying to extract only the text between the brackets and "AS Last_Partner_Shut_Down":
(SELECT     pth.ProgramId\n                       ,Last_Partner_Shut_Down_Date = MAX(pth.EventDate)\n             FROM       DW_Staging..Administration_Gen2_pay_programsTbl_History_Full AS pth\n             WHERE      pth.ProgramStatus = 1\n                        AND EXISTS (SELECT  1\n                                    FROM    DW_Staging..Administration_Gen2_pay_programsTbl_Full AS pt_in\n                                    WHERE   pt_in.ProgramId = pth.ProgramId\n                                            AND pt_in.ProgramStatus = 0)\n             GROUP BY   pth.ProgramId) AS Last_Partner_Shut_Down
When using "(\()(.*)(\))(.*)" in regex101 I get the desired groups:
But when running it in Python I get only "pth.EventDate" in group 2:
query = "(SELECT     pth.ProgramId\n                       ,Last_Partner_Shut_Down_Date = MAX(pth.EventDate)\n             FROM       DW_Staging..Administration_Gen2_pay_programsTbl_History_Full AS pth\n             WHERE      pth.ProgramStatus = 1\n                        AND EXISTS (SELECT  1\n                                    FROM    DW_Staging..Administration_Gen2_pay_programsTbl_Full AS pt_in\n                                    WHERE   pt_in.ProgramId = pth.ProgramId\n                                            AND pt_in.ProgramStatus = 0)\n             GROUP BY   pth.ProgramId) AS Last_Partner_Shut_Down"
sub_query = re.search("(\()(.*)(\)(.*))", query)
print(sub_query.group(2))
#Output: pth.EventDate
I imagine this has something to do with lazy/greedy quantifier but couldn't figured it out.
Thanks in advance.

