how does regular expression generate a database with information about a file name in python?

For the examples you have given, the following regex works:

import re

file_names = [
    'data - 05 A - Tea 2017.xls', 
    'data - 07 - C - Tea 2017.xls', 
    'data - 05 B - Tea 2017.xls',

for file_name in file_names:
    number, letter = re.findall('data - ([0-9]+).*([A-Z]) - Tea.*', file_name)[0]
    print(number, letter)

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top