Jan-06-2020, 06:09 PM
(Jan-06-2020, 05:18 PM)warden89 Wrote: . My directory has files that look like this: 20191210.092030_Monthly_Service_Cost_12-10-2019-02-17A would write regex to clean it up first,then add
Ultimately, I would like my zip file to look like MonthlyServiceCost.zip
.zip
.Example.
>>> import re >>> >>> s = '20191210.092030_Monthly_Service_Cost_12-10-2019-02-17' >>> r = re.search(r'_(.*[a-zA-Z])', s) >>> result = r.group(1).replace('_', '') >>> print(f'{result}.zip') MonthlyServiceCost.zip >>> >>> s = '9999.777.44_Monthly_Service_Cost_111-777_999.44' >>> r = re.search(r'_(.*[a-zA-Z])', s) >>> result = r.group(1).replace('_', '') >>> print(f'{result}.zip') MonthlyServiceCost.zip