Regex to extract Date from filename (4digit beginning with 19 or 20)

I'm trying to create an action for the Date tag where the four digit date is extracted from the filename,

such that it will satisfy both these conditions:

  • any number string of 4 digits
    ( ignoring number strings that are either more or less than 4 digits )
  • string must start with either 19 or 20

AND failing to meet these conditions, the Date tag won't be replaced.

You are looking for numbers between 1900 until 2099?
There are never classical pieces from 18xx or earlier?

I suppose 17 - 20 would be fine as well... Id seldom come across anything 18 or before.

so Yes, 1900-2099 , but 1700-2099 is fine too.

What, if your filename has multiple valid dates, like
Filename with date from 1701 over 1971 to 2022.mp3

Do you want the first or the last date in such a case?

only the first if more than one .

You can try this action:
Type: Format Value
Field: DATE (or whatever you want as tag to save the year into it)
Format string:

to fullfill your condition

AND failing to meet these conditions, the Date tag won't be replaced.

you have to (mandatory!) FILTER your songs BEFORE you use the above action, with
%_FILENAME% MATCHES ((17|18|19|20)\d{2})
otherwise you get the full filename for those not matching (not including 1700 until 2099) into your DATE.

As always for regular expressions:
Please test it on your backuped test data before you use it on your collection.

1 Like

Thank you very much for your time and expertise, I will test this as you suggested, and will return to edit this comment and click "solution" .

1 Like

Hint: I had to update the expression to get the FIRST (not the LAST) year as wished.

And once you have done that you could easily import the date data with
Mask: %year% %dummy%

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.