Reputation: 191
Objective: Use Python regex to return a list of filenames have certain file extensions.
List of files:
Regex to find files that end in *.ROM or 3x numbers:
bios_file = re.findall(r'.*\.(rom|[0-9]{3})+', name, re.I)
Issue:
bios_file is returning ['ROM'], ['rom'], [928]
. bios_file should be returning the entire filename ['X8SIA9.ROM'],
etc. How can I have the full filename returned instead of just the file extension?
Upvotes: 0
Views: 85
Reputation: 49320
You're not capturing the whole filename in the group. You can also use noncapturing groups with (?:...)
.
.*\.(rom|[0-9]{3})+ # from this
(.*\.(?:rom|[0-9]{3})) # to this
Upvotes: 3