# Remove spaces from tags

**URL:** <https://community.mp3tag.de/t/remove-spaces-from-tags/19129>\
**Category:** Support\
**Created:** [July 8, 2017, 10:31am UTC](https://community.mp3tag.de/t/remove-spaces-from-tags/19129 "2017-07-08T10:31:37Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![senior](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/s/c37758/32.png) [@senior](https://community.mp3tag.de/u/senior)\
**Post date:** [July 8, 2017, 10:31am UTC](https://community.mp3tag.de/t/remove-spaces-from-tags/19129/1 "2017-07-08T10:31:37Z")

</div>

I want to remove spaces from a tag but all that I've tried so far either removes the complete tag or inserts charachters that I don't want. Now I beg for an idea how to do it correctly. There are two problems to be solved. One: A great number of tags contain leading and/or trailing spaces. These I want to remove and this should work when there is only a leading space or only a trailing space or both of them. Two: Sometimes there are two spaces in sequence within a tag and here I want to erase one of these spaces.  
Too difficult ? Well, yes as far as I'm concerned.

Please help me with a solution. Please don't assume that I am too familiar with regex and thos things, otherwise i wouldn't have asked. I use Mp3tag 2.83 and you may answer as well in German.

senior

---

<div class="post-metadata">

**Author:** ![stevehero](https://community.mp3tag.de/user_avatar/community.mp3tag.de/stevehero/32/337_2.png) [@stevehero](https://community.mp3tag.de/u/stevehero)\
**Post date:** [July 8, 2017, 10:59am UTC](https://community.mp3tag.de/t/remove-spaces-from-tags/19129/2 "2017-07-08T10:59:11Z")

</div>

Directly above this post there's a link to the Frequently Asked Questions: #howto:faq-frequently-asked-questions

You'll find the answer there under actions.

And many other basic functionalities of Mp3tag.

Although the answer there could be short handed to one action to.

**Action type** : Replace with regular expressions  
**Field** : \_TAG  
**Regular expression** : `^\s*|\s*$`  
**Replace matches with** :

---

<div class="post-metadata">

**Author:** ![senior](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/s/c37758/32.png) [@senior](https://community.mp3tag.de/u/senior)\
**Post date:** [July 8, 2017, 12:40pm UTC](https://community.mp3tag.de/t/remove-spaces-from-tags/19129/3 "2017-07-08T12:40:04Z")

</div>

Many thanks for the link to this tutorial which I must have overlooked as my search was more or less resultless. I'll go through these instruction and hope that I'll get along all by myself. Should I not succeed I'll ask again.

Have a nice weekend  
senior

---

<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:** [July 8, 2017, 1:52pm UTC](https://community.mp3tag.de/t/remove-spaces-from-tags/19129/4 "2017-07-08T13:52:46Z")

</div>

> [@senior](#):
>
> I want to remove spaces from a tag but all that I've tried so far either removes the complete tag or inserts charachters that I don't want. ...

Could you show us what you have done so far? Perhaps we can start there and you get a better idea what has to be done.  
Also, I would like to draw your attention to the help, in this case "scripting"

> **[Scripting Functions – Mp3tag Documentation](https://docs.mp3tag.de/scripting/)**
>
> Documentation on Mp3tag's scripting functions. Mp3tag is the universal Tag Editor.

and the $trim() function.

---

<div class="post-metadata">

**Author:** ![senior](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/s/c37758/32.png) [@senior](https://community.mp3tag.de/u/senior)\
**Post date:** [July 9, 2017, 3:24am UTC](https://community.mp3tag.de/t/remove-spaces-from-tags/19129/5 "2017-07-09T03:24:59Z")

</div>

> [@ohrenkino](#):
>
> Could you show us what you have done so far? Perhaps we can start there and you get a better idea what has to be done.  
> Also, I would like to draw your attention to the help, in this case "scripting" [https://docs.mp3tag.de/scripting](https://docs.mp3tag.de/scripting) and the $trim() function.

First of all: With the tutorial I was able to remove those spaces that I didn't want.  
My problem was (and still is) that I am absolutely dumb as to regex expressions. So it was necessary that I found something matching which I did. One problem was, that I triggered other actions before I noticed that I have to uncheck all other actionsgroups in the list. Here the undo function was of great help. Apparently other stored actions will be executed when they are in sequence with the wanted one and when they are checkmarked. What the checkmark is for, I still don't fully understand. Here is how my new actions look like (sorry they are in German as this is my native language)

![](https://community.mp3tag.de/uploads/default/original/2X/3/3244cfe23b223fa9d8c87cd87c39f2942e0f92f7.jpg)  
  
 ![](https://community.mp3tag.de/uploads/default/original/2X/7/71b56c6ace2bc575c73be85d25251c3ff4d9bd33.jpg)

Thank you all for your help  
senior

![](https://community.mp3tag.de/uploads/default/original/2X/3/3244cfe23b223fa9d8c87cd87c39f2942e0f92f7.jpg)

![](https://community.mp3tag.de/uploads/default/original/2X/7/71b56c6ace2bc575c73be85d25251c3ff4d9bd33.jpg)

---

<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:** [July 9, 2017, 6:13am UTC](https://community.mp3tag.de/t/remove-spaces-from-tags/19129/6 "2017-07-09T06:13:17Z")

</div>

> [@senior](#):
>
> First of all: With the tutorial I was able to remove those spaces that I didn't want.  
> My problem was (and still is) that I am absolutely dumb as to regex expressions....

If you only want to treat single/specific fields then it might be just as easy to use the $trim() function in an action of the type "Format value"  
Field: ARTIST  
Format string: $trim(%artist%)  
No regular expression required.

you can actually filter for such fields:  
"$if($eql($len(%artist%),$len($trim(%artist%))),1,0)" IS "0"  
(replace the %artist% with any other field name that you want to check)

The check boxes in the actions list enable you to create your own jobs when executing actions:  
You can compose the action groups in the required number and sequence (move them up and down in the list) to cater for specific tasks. Like this you do not have to call the same actions over and over again. MP3tag allows you to be as modular as you like.

---

<div class="post-metadata">

**Author:** ![senior](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/s/c37758/32.png) [@senior](https://community.mp3tag.de/u/senior)\
**Post date:** [July 9, 2017, 7:07am UTC](https://community.mp3tag.de/t/remove-spaces-from-tags/19129/7 "2017-07-09T07:07:33Z")

</div>

> [@ohrenkino](#):
>
> If you only want to treat single/specific fields then it might be just as easy to use the $trim() function in an action of the type "Format value"  
> Field: ARTIST  
> Format string: $trim(%artist%)  
> No regular expression required.
> 
> you can actually filter for such fields:  
> "$if($eql($len(%artist%),$len($trim(%artist%))),1,0)" IS "0"  
> (replace the %artist% with any other field name that you want to check)
> 
> The check boxes in the actions list enable you to create your own jobs when executing actions:  
> You can compose the action groups in the required number and sequence (move them up and down in the list) to cater for specific tasks. Like this you do not have to call the same actions over and over again. MP3tag allows you to be as modular as you like.

When I understand the filter expression correcly then the given example trims the leading first character of a string. Thank you for explaining the check boxes to me, that was very helpful for my understanding.

senior

---

<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:** [July 9, 2017, 7:23am UTC](https://community.mp3tag.de/t/remove-spaces-from-tags/19129/8 "2017-07-09T07:23:46Z")

</div>

> [@senior](#):
>
> When I understand the filter expression correcly then the given example trims the leading first character of a string. ...

Not quite:  
THe filter evaluates the length of the string in the field (in this example) ARTIST and compares it with the length of the string in the field ARTIST after the leading and trailing (both!) have been cut.  
Like this you find all the strings that have either leading or trailing blanks.

---

<div class="post-metadata">

**Author:** ![senior](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/s/c37758/32.png) [@senior](https://community.mp3tag.de/u/senior)\
**Post date:** [July 9, 2017, 9:31am UTC](https://community.mp3tag.de/t/remove-spaces-from-tags/19129/9 "2017-07-09T09:31:54Z")

</div>

> [@ohrenkino](#):
>
> Not quite:  
> THe filter evaluates the length of the string in the field (in this example) ARTIST and compares it with the length of the string in the field ARTIST after the leading and trailing (both!) have been cut.  
> Like this you find all the strings that have either leading or trailing blanks.

I slowly get the picture. Thanks for your patience!

---

<div class="post-metadata">

**Author:** ![DetlevD](https://community.mp3tag.de/user_avatar/community.mp3tag.de/detlevd/32/123_2.png) [@DetlevD](https://community.mp3tag.de/u/DetlevD)\
**Post date:** [July 9, 2017, 10:26am UTC](https://community.mp3tag.de/t/remove-spaces-from-tags/19129/10 "2017-07-09T10:26:32Z")

</div>

> [@senior](#):
>
> ... One problem was, that I triggered other actions before I noticed that I have to uncheck all other actionsgroups in the list. ... Apparently other stored actions will be executed when they are in sequence with the wanted one and when they are checkmarked. ...

Within the dialog "Action groups", at the top of the list of actiongroup names, I have inserted an everlasting check marked actiongroup entry called " **NO\_ACTION**", without any internal action defined, ... it is just a placeholder doing nothing.  
All following other defined actiongroups have no checkmark.

You can call an actiongroup by the Mp3tag menu "Actions" [Alt+A], then select a defined entry from the list of actiongroups.

For example, define an actiongroup to remove leading and trailing spaces from all tagfields within the entire TAG, having only one entry.  
Name this actiongroup to: &MyActions#Trim leading trailing &spaces (\_TAG)  
Field: \_TAG  
Regular expression: ^\s+|\s+$(?#remove leading trailing spaces)  
Replace matches with:   
case sensitive comparison: no

Afterwards this action group can be called by the Mp3tag menu [Alt+A] Actions etc., ...  
or directly by the keyboard combination [ALT+AMS].

DD.20170709.1426.CEST

---

<div class="post-metadata">

**Author:** ![senior](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/s/c37758/32.png) [@senior](https://community.mp3tag.de/u/senior)\
**Post date:** [July 10, 2017, 3:10am UTC](https://community.mp3tag.de/t/remove-spaces-from-tags/19129/11 "2017-07-10T03:10:45Z")

</div>

Thank you for providing such detailed information on that matter. Mp3tag is a very mighty tool but it requires a lot of knowledge, more than is provided in tutorials and help files. Therefore I appreciate such step-by-step guidance all the more when it contains an explanation of what happens.

senior

---

<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:** [January 24, 2025, 10:12am UTC](https://community.mp3tag.de/t/remove-spaces-from-tags/19129/12 "2025-01-24T10:12:07Z")

</div>

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