# Trim all tags using Format Values

**URL:** https://community.mp3tag.de/t/trim-all-tags-using-format-values/18775
**Category:** General Discussion
**Created:** [March 3, 2017, 11:21pm UTC](https://community.mp3tag.de/t/trim-all-tags-using-format-values/18775 "2017-03-03T23:21:48Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![MasterKaster](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/m/ec9cab/32.png) [@MasterKaster](https://community.mp3tag.de/u/MasterKaster)
#### Post date: [March 3, 2017, 11:21pm UTC](https://community.mp3tag.de/t/trim-all-tags-using-format-values/18775/1 "2017-03-03T23:21:48Z")

</div>

Using this method: [Actions](https://community.mp3tag.de/t/967/10) 

You have to create 2 Regex actions to trim Front and End whitespaces.

 

I want to do trimming with **Format Values** :

 
- Field: \_TAG
- Format string: $trim(%\_tag%)

---

<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: [March 4, 2017, 9:29am UTC](https://community.mp3tag.de/t/trim-all-tags-using-format-values/18775/2 "2017-03-04T09:29:39Z")

</div>

> [@MasterKaster](#):
>
> Using this method: [Actions](https://community.mp3tag.de/t/967/10)  
> You have to create 2 Regex actions to trim Front and End whitespaces.  
> ...

Further down that thread it also mentions the $trim() function that deletes leading and trailing spaces.  
Have you tried it?  
Although it could well be that $trim() looks at a whole field and then \_TAG is the complete string of all fields so that only the first and the last space are deleted.  
You would have to name the fields individually.

---

<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: [March 4, 2017, 6:40pm UTC](https://community.mp3tag.de/t/trim-all-tags-using-format-values/18775/3 "2017-03-04T18:40:05Z")

</div>

> [@MasterKaster](#):
>
> ... Regex actions to trim Front and End whitespaces ...

Action "Replace using Regular Expression"  
Field: \_TAG  
RegExp: ^\s\*|\s\*$  
Replace with:

DD.20170304.2040.CET

---

<div class="post-metadata">

### Author: ![Oblio](https://community.mp3tag.de/user_avatar/community.mp3tag.de/oblio/32/4828_2.png) [@Oblio](https://community.mp3tag.de/u/Oblio)
#### Post date: [April 26, 2021, 9:50am UTC](https://community.mp3tag.de/t/trim-all-tags-using-format-values/18775/4 "2021-04-26T09:50:13Z")

</div>

I just found a gotcha on this trim action that I have been using for years!

If you have a field with blank lines i.e. 2 consecutive CRLF e.g. a lyrics field with line spacing between verses, then this action will delete them because \s\*$ will match 2 CRLF.

You can use ^\h+|\h+$ instead. \h matches horizontal whitespace but not CRLF
