# Retain the first 10 characters and delete everything after

**URL:** https://community.mp3tag.de/t/retain-the-first-10-characters-and-delete-everything-after/63606
**Category:** Support
**Created:** [January 29, 2024, 4:55pm UTC](https://community.mp3tag.de/t/retain-the-first-10-characters-and-delete-everything-after/63606 "2024-01-29T16:55:39Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![Calysmin38](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/c/958977/32.png) [@Calysmin38](https://community.mp3tag.de/u/Calysmin38)
#### Post date: [January 29, 2024, 4:55pm UTC](https://community.mp3tag.de/t/retain-the-first-10-characters-and-delete-everything-after/63606/1 "2024-01-29T16:55:39Z")

</div>

Currently, I have the following pattern for my filenames (these are some examples):

1981-03-01-Kim Carnes-Bette Davis Eyes.mp3  
1981-07-01-Soft Cell-Tainted Love.mp3  
1982-01-22-Huey Lewis and The News-Do You Believe in Love.mp3  
1982-06-01-Laura Branigan-Gloria.mp3

My YEAR field is blank. I would like for my YEAR field to become:

YYYY-MM-DD

Thus, for example, if this is my filename:

1981-03-01-Kim Carnes-Bette Davis Eyes

I want my YEAR field to go from blank to:

1981-03-01

Therefore, I would like to do a filename to tag conversion, where I keep the first 10 characters of the filename, and delete all characters after position 10, and this result becomes my YEAR field. The number of characters that need to be deleted after position 10 is variable, as can be seen in the above examples, but retaining the first 10 characters is always a constant. I've seen some examples where a specified number of leading characters are DELETED (for example, deleting the first ten leading characters: ^.{10}) and everything else after that is retained, but I need the other way around. And I don't think I can specify a certain number of TRAILING characters to be deleted because the number of trailing characters to be deleted (as noted above) is variable.

I couldn't figure out how to do this with %guess% (guess values) because there are dashes in the YYYY-MM-DD syntax but also dashes in the rest of the expression. The delimiter (the dash) immediately following YYYY-MM-DD isn't unique and occurs within the characters that I want to keep.

For example, I tried this:

Convert  
Filename - Tag  
Format String: %year% %guess%

The result:

Filename: 1981-03-01-Kim Carnes-Bette Davis Eyes.mp3  
YEAR: 1981-03-01-Kim

I also tried to figure out how to do this with a regular expression (regexp) - retain first 10 characters and remove everything thereafter. I found something on a general regular expression discussion forum (not mp3tag) regarding "how to remove all but the first n characters", and from looking over that I wondered if something like this might do it in mp3tag in 2 steps:

Step 1  
Convert  
Filename - Tag  
Format String: %YEAR%

Step 2  
Action:  
Replace with regular expression  
Field: %YEAR%  
Regular expression: $regexp(^(.{10}).\*$)  
Replace matches with: \1

However, even if this "replace with regular expression" approach is on the right path, I don't think I have the correct syntax because I don't understand regular expression syntax very well in general. The above action (Step 2) did not work; nothing changed.

Perhaps this is much easier than I am making it and can be done rather simply without regexp?

Any assistance is appreciated.

---

<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 29, 2024, 5:02pm UTC](https://community.mp3tag.de/t/retain-the-first-10-characters-and-delete-everything-after/63606/2 "2024-01-29T17:02:44Z")

</div>

You could try an action of the type "Format value" or Convert\>Tag-Tag for YEAR  
Format string: `$regexp(%_filename%,(.*?)-\u.*,$1)`

Please note that the field YEAR is supposed to have only 4 digits according to the ID3 standard.  
If you want to use such a longer date, consider the use of RELEASETIME

> **[Tag Field Mappings – Mp3tag Documentation](https://docs.mp3tag.de/mapping/#releasetime)**
>
> Overview of all available tag fields, their names in Mp3tag, and how they are mapped to the internal structures of the different tag formats. Mp3tag is the universal Tag Editor.

You could simply shorten that longer date for the use in YEAR.

---

<div class="post-metadata">

### Author: ![Calysmin38](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/c/958977/32.png) [@Calysmin38](https://community.mp3tag.de/u/Calysmin38)
#### Post date: [January 29, 2024, 5:11pm UTC](https://community.mp3tag.de/t/retain-the-first-10-characters-and-delete-everything-after/63606/3 "2024-01-29T17:11:01Z")

</div>

Thanks very much for the prompt reply! That works perfectly.

Here is what I did:

Step 1  
Convert  
Filename - Tag  
Format String: %YEAR%

Step 2  
Convert  
Tag - Tag  
Field: YEAR  
Format string:  
`$regexp(%_filename%,(.*?)-\u.*,$1)`

Thanks for the info regarding the ID3 standard for YEAR being only 4 digits. I'll consider using RELEASETIME for my YYYY-MM-DD date with YEAR being just the four-digit year.

---

<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 29, 2024, 5:18pm UTC](https://community.mp3tag.de/t/retain-the-first-10-characters-and-delete-everything-after/63606/4 "2024-01-29T17:18:13Z")

</div>

TBH, step 1 is not really necessary, as you overwrite YEAR with step 2.  
Use step2 as step1 but not for YEAR but for RELEASETIME.  
Create a new step 2 with an action of the type "Format value" or use Convert\>Tag-Tag for YEAR  
Format string: `$num(%releasetime%,1)`  
this should strip the first part from RELEASETIME up to the first non-digit character which is the hyphen.

---

<div class="post-metadata">

### Author: ![Calysmin38](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/c/958977/32.png) [@Calysmin38](https://community.mp3tag.de/u/Calysmin38)
#### Post date: [January 29, 2024, 6:12pm UTC](https://community.mp3tag.de/t/retain-the-first-10-characters-and-delete-everything-after/63606/5 "2024-01-29T18:12:37Z")

</div>

Thank you! I practiced your 2-step procedure for RELEASETIME and YEAR and it works great. And I see why your original solution does not require two steps as I had at first thought; I practiced that as well and successfully did the TAG-TAG conversion in 1 step to fill the blank YEAR field from the first 10 characters of filename.

Here is my summary of the two procedures:

Procedure 1: Put YYYY-MM-DD in YEAR field from first 10 characters of filename:  
-1 step  
-however, doesn't comply with 4-digit ID3 standard for YEAR field

Convert  
Tag - Tag  
Field: YEAR  
Format string: `$regexp(%_filename%,(.*?)-\u.*,$1)`

Procedure 2: Put YYYY-MM-DD in RELEASETIME and YYYY in YEAR:  
-2 steps  
-complies with 4-digit ID3 standard for YEAR field

Step 1  
Convert  
Tag - Tag  
Field: RELEASETIME  
Format string: `$regexp(%_filename%,(.*?)-\u.*,$1)`

Step 2  
Convert  
Tag - Tag  
Field: YEAR  
Format string: `$num(%releasetime%,1)`

---

<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 28, 2024, 6:13pm UTC](https://community.mp3tag.de/t/retain-the-first-10-characters-and-delete-everything-after/63606/6 "2024-02-28T18:13:23Z")

</div>

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