List1 = ['ABCD_123.A_062320_082824', 'ABCD_123.A_062320_094024','ABCD_123.A_063020_084447']
I want to keep the last element as it has the latest time stamp MonDayYear_HrMinSec
Method 1
names = []
for name in list1:
names.append(name.split('_')[0])
Day = name.split('_')[-2]
Time = name.split('_')[-1]
print(names,Day,Time)
Method 2
for name in list1:
namematch = re.search(r'^([a-zA-Z0-9]*)(__[\d]*.A_)([\d]{6})_([\d]{6})',name)
names.append(namematch.group(1))
#print(names)
I tried regex which works but I dont know how to check for corresponding group. DO I use an if condition checking for group 2 and 3 and keep group1 or something along those lines?