0

Im trying to get one of each matching pattern using regex. Here is a sample of code im working with:

import re

fileName = '''(18080037-20200409161512367_l.jpg, 18080037-20200409161512451_l.jpg,18080037-20200409161512534_l.jpg,18080037-20200409161512617_l.jpg,18080037-20200409161512701_l.jpg,18080037-20200409161512784_l.jpg,18080037-20200409161512867_l.jpg,18080037-20200409161512951_l.jpg,18080037-20200409161513034_l.jpg,18080037-20200409161513117_l.jpg,18080037-20200409161513200_l.jpg,18080037-20200409161513284_l.jpg,18080037-20200409161513367_l.jpg,18080037-20200409161513450_l.jpg,18080037-20200409161513534_l.jpg,18080037-20200409161513617_l.jpg,18080037-20200409161513700_l.jpg,18080037-20200409161513784_l.jpg,18080037-20200409161513867_l.jpg,18080037-20200409161513950_l.jpg,18080037-20200409161514034_l.jpg,18080037-20200409161514117_l.jpg,18080037-20200409161514200_l.jpg)'''

fileRegex = re.compile(r'(\d{14})')

mo = fileRegex.findall(fileName)

print(mo)

So my goal is to isolate this group 20200409161514 but with my current setup it grabs every file. I dont need every file. I just want the first instance of every file change. So end result should look like:

20200409161512

20200409161513

20200409161514

This way i can isolate the files and copy those over to a different directory.

I apologize if this has been answered, i wasnt able to find anything. Also if im barking up the wrong tree a point in the right direction on how to do this would be helpful. Thank You !!

cubick
  • 293
  • 3
  • 13

0 Answers0