I have a file name which always ends on a number proceeding with its file extension such as:
filename = 'photo_v_01_20415.jpg'
From its filename I need to extract the file_extension and the last number that sits right before the file extension itslelf. As a result of split I should have two strings:
original_string = 'photo_v_01_20415.jpg'
string_result_01 = `photo_v_01_` (first half of the file name)
string_result_02 = `20415.jpg` (second half of the file name).
The problem is that the incoming filenames will be inconsistent. The last number could be separated from its file_name by underscore "_", by empty space " ", by period "." or anything else. Example of possible file names:
photo_v_01_20415.jpg
photo_v_01.20415.jpg
photo_v_01 20415.jpg
photo_v_01____20415.jpg
It appears I need to be using re. expressions with re.search or re.sub. I would appreciate for any suggestions!