# Trimming all but last four characters from a field

**URL:** <https://community.mp3tag.de/t/trimming-all-but-last-four-characters-from-a-field/59724>\
**Category:** Support\
**Created:** [January 17, 2023, 3:53pm UTC](https://community.mp3tag.de/t/trimming-all-but-last-four-characters-from-a-field/59724 "2023-01-17T15:53:34Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![droid\_uprising](https://community.mp3tag.de/user_avatar/community.mp3tag.de/droid_uprising/32/13090_2.png) [@droid\_uprising](https://community.mp3tag.de/u/droid_uprising)\
**Post date:** [January 17, 2023, 3:53pm UTC](https://community.mp3tag.de/t/trimming-all-but-last-four-characters-from-a-field/59724/1 "2023-01-17T15:53:34Z")

</div>

I need to write a function to trim all but the last four digits from the date (%YEAR% i think) of a bunch of MP3s. Currently most of them have "January 1, 2000" formatting and i would like to have everything other than the year removed.

I hope my question made sense and thank you for any help!

---

<div class="post-metadata">

**Author:** ![MotleyG](https://community.mp3tag.de/user_avatar/community.mp3tag.de/motleyg/32/440_2.png) [@MotleyG](https://community.mp3tag.de/u/MotleyG)\
**Post date:** [January 17, 2023, 3:58pm UTC](https://community.mp3tag.de/t/trimming-all-but-last-four-characters-from-a-field/59724/2 "2023-01-17T15:58:10Z")

</div>

If it is always the last 4 characters you can use the function  
`"$right(%year%,4)"`

---

<div class="post-metadata">

**Author:** ![ohrenkino](https://community.mp3tag.de/user_avatar/community.mp3tag.de/ohrenkino/32/4843_2.png) [@ohrenkino](https://community.mp3tag.de/u/ohrenkino)\
**Post date:** [January 17, 2023, 3:59pm UTC](https://community.mp3tag.de/t/trimming-all-but-last-four-characters-from-a-field/59724/3 "2023-01-17T15:59:03Z")

</div>

You could try an action of the type "Replace with regular expression" for YEAR  
Search string: `.*(\d\d\d\d)`  
Replace with: $1

---

<div class="post-metadata">

**Author:** ![droid\_uprising](https://community.mp3tag.de/user_avatar/community.mp3tag.de/droid_uprising/32/13090_2.png) [@droid\_uprising](https://community.mp3tag.de/u/droid_uprising)\
**Post date:** [January 17, 2023, 4:19pm UTC](https://community.mp3tag.de/t/trimming-all-but-last-four-characters-from-a-field/59724/4 "2023-01-17T16:19:42Z")

</div>

This worked, but I'm wondering if there is some redundancy in how I used this function.

When I create an action type of "Format Value" I am prompted to choose a field, (in this case YEAR), and I'm wondering if this makes part of "$right(%year%,4)" redundant and if this could cause any problems. I will be saving this function to use whenever I convert from my FLAC collection to MP3.

And thank you for the fast reply!

---

<div class="post-metadata">

**Author:** ![LyricsLover](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/l/c6cbf5/32.png) [@LyricsLover](https://community.mp3tag.de/u/LyricsLover)\
**Post date:** [January 17, 2023, 4:20pm UTC](https://community.mp3tag.de/t/trimming-all-but-last-four-characters-from-a-field/59724/5 "2023-01-17T16:20:53Z")

</div>

It is not redundant, because you can write the content of `$right(%year%,4)` - the 4 numbers `2000` in your example - in every tag you want. Not only into the choosen YEAR tag, but also into every other tag.

If you choose YEAR in this case, you overwrite the current content "January 1, 2000" with "2000".  
If you would choose another tag like COMMENT as Field:  
 ![image](https://community.mp3tag.de/uploads/default/original/2X/7/7add7b0b6514d208905d956d7e2257ae5b367fd0.png)  
you would copy the part "2000" from YEAR and write it into COMMENT.  
The YEAR tag would be left unchanged, the current content of COMMENT would be replaced.

---

<div class="post-metadata">

**Author:** ![droid\_uprising](https://community.mp3tag.de/user_avatar/community.mp3tag.de/droid_uprising/32/13090_2.png) [@droid\_uprising](https://community.mp3tag.de/u/droid_uprising)\
**Post date:** [January 17, 2023, 4:51pm UTC](https://community.mp3tag.de/t/trimming-all-but-last-four-characters-from-a-field/59724/6 "2023-01-17T16:51:57Z")

</div>

Got it, hadn't properly wrapped my head around the answer yet but this makes complete sense now. Thank you to everyone!

---

<div class="post-metadata">

**Author:** ![MotleyG](https://community.mp3tag.de/user_avatar/community.mp3tag.de/motleyg/32/440_2.png) [@MotleyG](https://community.mp3tag.de/u/MotleyG)\
**Post date:** [January 17, 2023, 4:52pm UTC](https://community.mp3tag.de/t/trimming-all-but-last-four-characters-from-a-field/59724/7 "2023-01-17T16:52:15Z")

</div>

I guess this really depends on what your end requirement is. If you don't want to keep the month and date (I don't think too many players will respond to "January") then discarding this info when replacing the lengthy %year% tag value with the newly updated 4 digits isn't redundant. However if you feel that you may need to keep that original data intact for some future purpose, you may want to at least copy that info to a custom tag field for now. Then you can update the actual %year% tag and still have both. The amount of data consumed for this is really insignificant compared to the music anyhow.

---

<div class="post-metadata">

**Author:** ![droid\_uprising](https://community.mp3tag.de/user_avatar/community.mp3tag.de/droid_uprising/32/13090_2.png) [@droid\_uprising](https://community.mp3tag.de/u/droid_uprising)\
**Post date:** [January 17, 2023, 5:43pm UTC](https://community.mp3tag.de/t/trimming-all-but-last-four-characters-from-a-field/59724/8 "2023-01-17T17:43:07Z")

</div>

My confusion was me not realizing how the format string actually worked, the "year" being used to _call from_ a field while _writing_ to a field was handled separately. It all makes sense now and from here I think I can probably cobble together my own arguments once I find a list of fields and functions. Thank you again!

---

<div class="post-metadata">

**Author:** ![ohrenkino](https://community.mp3tag.de/user_avatar/community.mp3tag.de/ohrenkino/32/4843_2.png) [@ohrenkino](https://community.mp3tag.de/u/ohrenkino)\
**Post date:** [January 17, 2023, 5:45pm UTC](https://community.mp3tag.de/t/trimming-all-but-last-four-characters-from-a-field/59724/9 "2023-01-17T17:45:21Z")

</div>

> [@droid\_uprising](#):
>
> once I find a list of fields and functions

No easier said than done - see the documentation:

> **[Mp3tag Documentation](https://docs.mp3tag.de/)**
>
> Mp3tag is the universal Tag Editor. It supports editing of metadata and cover art for many different audio and video formats (MP3, MP4, FLAC, WAV, ...), file renaming, metadata import and repeatable actions.

---

<div class="post-metadata">

**Author:** ![system](https://community.mp3tag.de/uploads/default/original/2X/c/ce7035d426cb755a7916793326d23b465222a407.png) [@system](https://community.mp3tag.de/u/system)\
**Post date:** [February 16, 2023, 5:45pm UTC](https://community.mp3tag.de/t/trimming-all-but-last-four-characters-from-a-field/59724/10 "2023-02-16T17:45:51Z")

</div>

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