Leaving only the year

Hi

I'm trying to change some titles to leave only the year.

For example

Children Of The Sun (The Missunderstood 1967)
A Touch Of Velvet A Sting Of Brass 2 (The Mood Mozaic 1966)
All Along The Watchtower (The Alan Bown 1967)
Azrael (The Nice 1967)
But Cry (The Robb Storm Group 1966)

Would become

1967
1966
1967
1967
1966

Can someone advise on how to achieve this?

Grateful for any help.

:slight_smile:

Try Convert>Tag - Tag or an action of the type "Format value" for the field
Formatstring: $regexp('Children Of The Sun (The Missunderstood 1967)','.* (\d\d\d\d)\)',$1)
In which you replace the search string with the field name.

A more universal solution would be:
Actions → Actions (Quick) → Replace with regular expression
Field:
TITLE
Regular expression:
^.*(\d{4}).*$
Replace matches with:
$1

Your suggestion would also treat
MB Trac 1100
Deutz D9006
IHC 1046
Herbert Grönemeyer - 4630 Bochum
Spliff - 85555
Wilson Picket - 634-5789 - Soulsville, U.S.A.
Vice - Steady 1234

@chayes
Maybe you could also tell us why you would like to reduce the content of the TITLE to 4 numbers?

These 4 numbers usually are the content of the YEAR or ORIGYEAR tag or maybe part of one of the date tags.

In which use cases would it be helpful to fill the TITLE with only 4 numbers?

Hi all

Thanks for your help. I applied this

and it works perfectly! It leaves the year and removes the text in exactly the way I was seeking. :slight_smile:

BTW For my curiosity , how would the expression be modified to remove the year and leave only the text? :slight_smile:

If you want to split the existing data into TITLE and YEAR I would suggest an action of the type "Guess value"
Source pattern: %title%
Target format string: %title% (%year%)

And a comment on

please see that the code also treats data that you may not want to treat as shown in a short list of examples in

You may have others.

Assuming that you also want to remove the space before the year, this would do the trick:
Actions → Actions (Quick) → Replace with regular expression
Field:
TITLE
Regular expression:
^(.*) \d{4}(.*)$
Replace matches with:
$1$2

However, as @ohrenkino mentioned, this only works cleanly if your files all follow the pattern of your examples and may lead to unwanted/unexpected results if you have multiple 4-digit numbers in the strings.

Many thanks. That does the job!

I understand the issue with other random 4-digit numbers in the title , but that should be the exception so will be manageable.

:slight_smile:

BTW

I think a way around the issue with more accurately identifying Year might be to have the regex only select four digits beginning with 19* and 20* in the two scenarios. Is this possible?

:slight_smile:

I think you started off fairly nicely with the parenthesis around the year.
The

would take any 4 digits, even 4 digits which are part of numbers with more digits whereas the pattern that looks for parenthesis with 4 digits inside has a higher hit rate.
Even if you look for titles that have a 19 or 20 at the beginning, you would get hits with titles like
After the fire: 1980-F
or
20000 Meilen
New Order - 1963
Green Day - 2000 Lightyears
Kraftwerk - Expo 2000

The expression would look like: .*((19|20)\d\d).*

I've played around with it a bit and while it won't eliminate all false matches, this one is pretty solid, at least for most examples provided in this thread:

^.*((19|20)\d{2})(?![\d-]).*$


And if the year is always followed by closing parenthesis and is preceded by a space, this would eliminate all mismatches (in the given examples).

^.* ((19|20)\d{2})\).*$

If you really want to go the specific route, this matches his examples pretty exactly.

^[\w ]+ \([\w ]+ ((19|20)\d{2})\)$

However, then it's no longer "universal". My initial proposed solution matches his examples well enough while still allowing other versions. Filtering and (more importantly) manually checking results are important when using any regex you don't fully understand and/or have tested.

I think most of us are wondering why you want a song's filename reduced to a year. You can only have one song per year. Just Curious.

Thanks for your help guys. Problem solved!

:slight_smile: :slight_smile:

For those wondering I'm just trying to strip out dates / text from certain Filenames either for their own sake , or to put the year back in a different place.