# Create new field by trimming existing tags

**URL:** https://community.mp3tag.de/t/create-new-field-by-trimming-existing-tags/57500
**Category:** Mac
**Created:** [June 3, 2022, 7:30am UTC](https://community.mp3tag.de/t/create-new-field-by-trimming-existing-tags/57500 "2022-06-03T07:30:56Z")
**Posts on this page:** 15
**Page:** 1

<div class="post-metadata">

### Author: ![phso](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/p/439d5e/32.png) [@phso](https://community.mp3tag.de/u/phso)
#### Post date: [June 3, 2022, 7:30am UTC](https://community.mp3tag.de/t/create-new-field-by-trimming-existing-tags/57500/1 "2022-06-03T07:30:56Z")

</div>

Hi everyone-

I have %unsyncedlyrics% populated for my songs. They always begin in either one of the following formats:

**(A)**

> eng||ComposerA: Abc/Def  
> LyricistA: Ghi/Jkl  
> ArrangerA: Mno/Pqr  
> ProducerA: Stu/Vwx
> 
> (Lyrics blah blah blah)

Or, **(B)**

> eng||ComposerB: Abc/Def  
> LyricistB: Ghi/Jkl  
> ArrangerB: Mno/Pqr  
> ProducerB: Stu/Vwx
> 
> (Lyrics blah blah blah)

I want to feed this data into the fields: **%composer%** , **%lyricist%** , **%arranger%** , and **%producer%**.

_Think of **ComposerA** and **ComposerB** as "composer" written in different languages, e.g. "Composer" for an English song, but "Compositeur" for a French song. (Idk, I'm just making stuff up - I don't think it'd matter much as it'll just be a search term.)_

Below is as far as I got:

> $mid(%unsyncedlyrics%,$add($strchr(%unsyncedlyrics%,Composer: ),10),$sub($strchr(%unsyncedlyrics%,Lyricist: ),$add($strchr(%unsyncedlyrics%,Composer: ),10)))

The "10" represents the length of "Composer: ", so it will return the text after "...ser: " and not "Com...".

This does not take into account the A OR B option. However, the issue I have now is that, it seems like the line spacing is giving me errors. When running this code, in the %composer% field, I see:

> Abc/Def...

Or

> Abc/Def  
> (blank line)

That is, the composer field is also capturing the line break, which I do not want. I tried trimming it by one character, but that doesn't work.

Could anyone please help. Much 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: [June 3, 2022, 8:12am UTC](https://community.mp3tag.de/t/create-new-field-by-trimming-existing-tags/57500/2 "2022-06-03T08:12:32Z")

</div>

Try an action of the type "Guess value" (Import tag fields)  
Source: `$regexp(%unsyncedlyrics%,'.*ComposerA: (.*?)\s*LyricistA: (.*?)\r\n\s*ArrangerA: (.*?)\r\n\s*ProducerA: (.*?)\r\n\s*.*',$1==$2==$3==$4)`  
Target format string: %composer%==%lyricist%==%arranger%==%producer%

You would have to replate the ComposerA etc. text with the real text.  
It will not work for different spellings in different languages. YOu would have to create an individual action for each string variation.

---

<div class="post-metadata">

### Author: ![phso](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/p/439d5e/32.png) [@phso](https://community.mp3tag.de/u/phso)
#### Post date: [June 3, 2022, 8:28am UTC](https://community.mp3tag.de/t/create-new-field-by-trimming-existing-tags/57500/3 "2022-06-03T08:28:27Z")

</div>

For now I will aim for just 1 language - and I got some progress extracting Composer, Lyricist, and Arranger.

$mid(%unsyncedlyrics%,$add($strchr(%unsyncedlyrics%,Composer: ),10),$sub($strchr(%unsyncedlyrics%,Lyricist: ),$add($strchr(%unsyncedlyrics%,Composer: ),10)))

As mentioned earlier, for composer, I'm finding everything to the right of "Composer: ", and before the left of "Lyricist: ".

The outstanding question now is for Producer. I can find everything to the right of "Producer: ", but I need to tell where to stop. (at the line break). Any idea on how to search for that line break?

---

<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: [June 3, 2022, 8:31am UTC](https://community.mp3tag.de/t/create-new-field-by-trimming-existing-tags/57500/4 "2022-06-03T08:31:55Z")

</div>

Have you tried my example?  
You can test the regular expression in Converter\>tag-Tag.  
If that gives you  
`Abc/Def==Ghi/Jkl==Mno/Pqr==Stu/Vwx`  
then you should be able to extract all the fields with the suggested action.

---

<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: [June 3, 2022, 8:35am UTC](https://community.mp3tag.de/t/create-new-field-by-trimming-existing-tags/57500/5 "2022-06-03T08:35:59Z")

</div>

> [@phso](#):
>
> $mid(%unsyncedlyrics%,$add($strchr(%unsyncedlyrics%,Composer: ),10),$sub($strchr(%unsyncedlyrics%,Lyricist: ),$add($strchr(%unsyncedlyrics%,Composer: ),10)))

This does not assign the strings to any field.  
The "Guess value" action that I suggest does just that.

---

<div class="post-metadata">

### Author: ![phso](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/p/439d5e/32.png) [@phso](https://community.mp3tag.de/u/phso)
#### Post date: [June 3, 2022, 8:49am UTC](https://community.mp3tag.de/t/create-new-field-by-trimming-existing-tags/57500/6 "2022-06-03T08:49:44Z")

</div>

I tried but that didn't populate the fields. I am simplifying my ask to this: Instead of composer lyricist arranger producer, in the %unsyncedlyrics% the field will be as follows:

A:  
B:  
C:  
D:

So I added the action to import tag fields, and I used the same target format string you provided.

`$regexp(%unsyncedlyrics%,'.*A: (.*?)\s*B: (.*?)\r\n\s*C: (.*?)\r\n\s*D: (.*?)\r\n\s*.*',$1==$2==$3==$4)`

I also tried the follwoing incase it's a typo but htat didn't work as well.

`$regexp(%unsyncedlyrics%,'.*A: (.*?)\r\n\s*B: (.*?)\r\n\s*C: (.*?)\r\n\s*D: (.*?)\r\n\s*.*',$1==$2==$3==$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: [June 3, 2022, 10:03am UTC](https://community.mp3tag.de/t/create-new-field-by-trimming-existing-tags/57500/7 "2022-06-03T10:03:28Z")

</div>

Did you try the regular expression Converter\>tag-Tag?

Alternatively: could you supply the contents of a real field instead of these made-up examples?  
Because, naturally, I succeed with your dummy data in a lyrics field:

 ![grafik](https://community.mp3tag.de/uploads/default/original/2X/3/367dcdbd25da303002852676abc266cae624b5f3.png)

(This was for testing the regular expression - so it does not matter that I selected the field COMMENT as target)

---

<div class="post-metadata">

### Author: ![phso](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/p/439d5e/32.png) [@phso](https://community.mp3tag.de/u/phso)
#### Post date: [June 3, 2022, 3:49pm UTC](https://community.mp3tag.de/t/create-new-field-by-trimming-existing-tags/57500/8 "2022-06-03T15:49:06Z")

</div>

Thanks so much for your help. Please see below

> eng||Composer: Johnny YimC  
> Lyricist: -  
> Arranger: Johnny YimA  
> Producer: Gary Chan/Johnny Yim
> 
> La la la

![tag1](https://community.mp3tag.de/uploads/default/original/2X/8/85d73d73093b49c86b8870ab9b83633bcabc3c59.png)

See below for results:

 ![tag](https://community.mp3tag.de/uploads/default/original/2X/9/91dbba68b757c1ddb7ce5c490355aaa0d5355411.png)

Being a music-only track (no lyrics in the song) - that's why there's a dash for the lyricist field. I'd like to feed the - into the lyricist field as well.

---

<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: [June 3, 2022, 4:20pm UTC](https://community.mp3tag.de/t/create-new-field-by-trimming-existing-tags/57500/9 "2022-06-03T16:20:52Z")

</div>

Oh, you are on a Mac!  
Please try to enclose also the last, the result string in apostrophes.  
(I cannot test this as I haven't got a Mac).  
But that is why I asked you to test the regular expression first.  
Perhaps someone else can chime in if the expected result cannot be achieved by you on your own.

---

<div class="post-metadata">

### Author: ![phso](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/p/439d5e/32.png) [@phso](https://community.mp3tag.de/u/phso)
#### Post date: [June 3, 2022, 4:51pm UTC](https://community.mp3tag.de/t/create-new-field-by-trimming-existing-tags/57500/10 "2022-06-03T16:51:31Z")

</div>

Thanks fo ryour prompt response... I tried adding apostrophes/quotes to the result string and that didn't work. Also tried single/double quotes and that didn't work as well.

---

<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: [June 3, 2022, 5:09pm UTC](https://community.mp3tag.de/t/create-new-field-by-trimming-existing-tags/57500/11 "2022-06-03T17:09:37Z")

</div>

I would suggest that you build the regular expression from scratch and watch the preview to see how the result changes, e.g. start with  
`$regexp(%unsyncedlyrics%,'.*ComposerA: (.*?)\s*\r\n.*','$1')`  
and see if that returns the string following "Composer: "  
As soon as you got that working, you can add the other parts.

---

<div class="post-metadata">

### Author: ![phso](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/p/439d5e/32.png) [@phso](https://community.mp3tag.de/u/phso)
#### Post date: [June 3, 2022, 6:22pm UTC](https://community.mp3tag.de/t/create-new-field-by-trimming-existing-tags/57500/12 "2022-06-03T18:22:16Z")

</div>

This is what I got:

`$regexp(%unsyncedlyrics%,'.*Composer: (.*?)\n*Lyricist: (.*?)\n*Arranger: (.*?)\n*Producer: (.*?)\n*',$1==$2==$3==$4)`

Composer/Lyricist/Arranger work perfectly, and now I'm back to the initial trouble with the producer line - It doesn't know where to stop because it's not reading the line break character...

Thanks again ohrenkino for your guidance thus far.

---

<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: [June 3, 2022, 6:23pm UTC](https://community.mp3tag.de/t/create-new-field-by-trimming-existing-tags/57500/13 "2022-06-03T18:23:56Z")

</div>

the expression should be  
`$regexp(%unsyncedlyrics%,'.*Composer: (.*?)\n*Lyricist: (.*?)\n*Arranger: (.*?)\n*Producer: (.*?)\n.*',$1==$2==$3==$4)`

---

<div class="post-metadata">

### Author: ![phso](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/p/439d5e/32.png) [@phso](https://community.mp3tag.de/u/phso)
#### Post date: [June 3, 2022, 6:43pm UTC](https://community.mp3tag.de/t/create-new-field-by-trimming-existing-tags/57500/14 "2022-06-03T18:43:40Z")

</div>

> [@ohrenkino](#):
>
> $regexp(%unsyncedlyrics%,'._Composer: (._?)\n_Lyricist: (._?)\n_Arranger: (._?)\n_Producer: (._?)\n.\*',$1==$2==$3==$4)

Negative...

This is the `%unsyncedlyrics%`:

> eng||Composer: Mark Lui  
> Lyricist: Aarif Rahman  
> Arranger: Mark Lui  
> Producer: Mark Lui
> 
> When I hear...

Using this code-  
`$regexp(%unsyncedlyrics%,'.*Composer: (.*?)\n*Lyricist: (.*?)\n*Arranger: (.*?)\n*Producer: (.*?)\n*',$1==$2==$3==$4)`

I get this-

 ![A](https://community.mp3tag.de/uploads/default/original/2X/4/4aa137278a663f758e26e0b31a2b4ddb84dbeb9f.png)

So it's able to identify the first 3 fields, and it just doesn't know where to stop.

Using the other code-  
`$regexp(%unsyncedlyrics%,'.*Composer: (.*?)\n*Lyricist: (.*?)\n*Arranger: (.*?)\n*Producer: (.*?)\n.*',$1==$2==$3==$4)`  
where the difference is the period in the end \n.\* (vs \n\*)...

I get this-

 ![B](https://community.mp3tag.de/uploads/default/original/2X/2/2b3e20ad80eccf4e2508bb42d845302debeaa60b.png)

Here, it's seems like it is unable to extract any data so it just spit out the full `%unsyncedlyrics%`.

---

<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: [June 3, 2022, 6:50pm UTC](https://community.mp3tag.de/t/create-new-field-by-trimming-existing-tags/57500/15 "2022-06-03T18:50:22Z")

</div>

> [@phso](#):
>
> and it just doesn't know where to stop.

In the WIndows world the lines are terminated by `\r\n`.  
So perhaps you add the `\r` to each field ...  
The `.*` means "any number of characters" so that should describe the (unwanted) rest.

In the original suggestion I had `\s*` to match any number of white space characters.  
So, sorry, I can't help you from the distance. You would need to experiment a little more with the dots and asterisks.
