I'm bad at regular expression so was hoping to get some feedback on this particular regex expression.
I have a list of file name, obtained from the os library's listdir method. The filenames will start with text like "D#######". So there may be D0000001.txt, D0000000.svg, D0000003.stl, etc. If the list is something like:
['D0000001.txt', 'D0000001.xlsx', 'D0000002.txt', 'D0000002.svg', 'D0000003.stl', 'D0000003.doc']
I want to all strings in the list that begin with 'D0000002'.
Will the regex 'D0000002*\.[a-zA-Z]{3}'
always ONLY return a match object for 'D0000002.txt' & 'D0000002.svg', and nothing else, or is it possible this pattern could match other values?
Note that there is no guarantee that the filename preceding the extension will only contain the "D" + 8 digits. So it is possible for filenames like "D1234567_someMoreText_20230720.abc" to exist. And if the pattern is:
'D1234567*\.[a-zA-Z]{3}'
the file noted should result in a match.
BTW, the comparison logic iterates through the list of filenames, performing the re.search()
on each string in the list. That iteration adds matching names to a "matching files" list for return.
Thanks!