I used the following regular expression on pythex to test it:
(\d|t)(_\d+){1}\.
It works fine and I am primarily interested in group 2. That it works successfully is shown below:
However, I can't get Python to actually show me the correct results. Here's a MWE:
fn_list = ['IMG_0064.png',
'IMG_0064.JPG',
'IMG_0064_1.JPG',
'IMG_0064_2.JPG',
'IMG_0064_2.PNG',
'IMG_0064_2.BMP',
'IMG_0064_3.JPEG',
'IMG_0065.JPG',
'IMG_0065.JPEG',
'IMG-20150623-00176-preview-left.jpg',
'IMG-20150623-00176-preview-left_2.jpg',
'thumb_2595.bmp',
'thumb_2595_1.bmp',
'thumb_2595_15.bmp']
pattern = re.compile(r'(\d|t)(_\d+){1}\.', re.IGNORECASE)
for line in fn_list:
search_obj = re.match(pattern, line)
if search_obj:
matching_group = search_obj.groups()
print matching_group
The output is nothing.
However, the pythex above clearly shows two groups returned for each, the second should be present and hit off many more files. What am I doing wrong?