Home > database >  matching the frame identifier of a limited file sequence with regex
matching the frame identifier of a limited file sequence with regex

Time:07-18

I have some code that can use regex to filter and find a list of files.

I want to filter these files by their name, and select the final set of numbers in the filename.

for example, say I have this sequence of file names:

render1frame0001.png ... render1frame0200.png

Finding the last 4 digits isnt that hard. The issue is when the file name itself has numbers in it.

Some platforms have different margins for frame counts, so I need it to be able to match more or less than 4 characters, while also ignoring any numbers in the file name.

so in the example above, it would match 0001 through 0200, ignoring the 1 inside the filename.

I dont have much experience with regex and this particular problem seems a little niche, so I dont exactly know what to do here.

also, the files can possibly have other extensions, such as jpeg, so I guess it should also be able to work around different extensions.

Essentially I want to match the first occurrence of a group of numbers... but from the end of the string backwards. That behavior could possibly get around the extension and any extra numbers in the file name.

Is this possible?

CodePudding user response:

Since each string is a filename that include the file extension, you should be able to use the below regular expression, regardless of the file type:

(\d )\.[a-z] $

enter image description here enter image description here

For more details about regular expression follow this: Puzzling with Regular Expression

  • Related