# How to skip whitespace when extracting tags from filenames

**URL:** https://community.mp3tag.de/t/how-to-skip-whitespace-when-extracting-tags-from-filenames/11430
**Category:** Support
**Created:** [January 12, 2011, 2:29am UTC](https://community.mp3tag.de/t/how-to-skip-whitespace-when-extracting-tags-from-filenames/11430 "2011-01-12T02:29:49Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![alexworden](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/a/a5b964/32.png) [@alexworden](https://community.mp3tag.de/u/alexworden)
#### Post date: [January 12, 2011, 2:29am UTC](https://community.mp3tag.de/t/how-to-skip-whitespace-when-extracting-tags-from-filenames/11430/1 "2011-01-12T02:29:49Z")

</div>

Hi,

Sorry if this is an obvious question but I've read the FAQ and searched and can't figure this out.

I'm trying to parse tags from filenames / directory hierarchies. Some of the files have the format

```
%track%-%title%

```

and some have

```
%track% - %title%

```

or other variation of whitespace / no whitespace or even underscores instead of hyphens.

How can I write a Format string that will work for all variations? I'm a software engineer by trade, and I'm not stupid, but the FAQ does not explain how to use $replace scripts at all. It needs some concrete examples.

Thanks,

Alex

---

<div class="post-metadata">

### Author: ![pone](https://community.mp3tag.de/user_avatar/community.mp3tag.de/pone/32/272_2.png) [@pone](https://community.mp3tag.de/u/pone)
#### Post date: [January 12, 2011, 3:44am UTC](https://community.mp3tag.de/t/how-to-skip-whitespace-when-extracting-tags-from-filenames/11430/2 "2011-01-12T03:44:19Z")

</div>

> [@alexSF](#):
>
> %track%-%title%  
> and some have
> 
> ```
> %track% - %title%
> 
> ```
> 
> or other variation of whitespace / no whitespace or even underscores instead of hyphens.

Action: Guess Values  
Source: $trim($regexp(%_filename%,(.\*)(-|_)._,$1))@@@$trim($regexp(%\_filename%,._(-|\_)(.\*),$2))  
Formatstring: %track%@@@%title%

here is help for the scripting:  
[https://docs.mp3tag.de/scripting](https://docs.mp3tag.de/scripting)

and here for the regular expressions:  
[https://docs.mp3tag.de/actions/replace-regexp](https://docs.mp3tag.de/actions/replace-regexp)

EDIT:  
i used %artist% instead of %track% because i was reading your question not good enough.  
i fixed that now.

---

<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: [January 12, 2011, 8:14am UTC](https://community.mp3tag.de/t/how-to-skip-whitespace-when-extracting-tags-from-filenames/11430/3 "2011-01-12T08:14:46Z")

</div>

> [@alexSF](#):
>
> ... I'm trying to parse tags from filenames / directory hierarchies. Some of the files have the format
> 
> ```
> %track%-%title%
> 
> ```
> 
> and some have
> 
> ```
> %track% - %title%
> 
> ```
> 
> or other variation of whitespace / no whitespace or even underscores instead of hyphens.  
> How can I write a Format string that will work for all variations?...

This could work ...

Begin Action Group **Test 2011#20110112.Guess** 

Action #1  
_Actiontype 7:_ **Import tag fields (guess values)**  
_Source format:_ **$regexp(%\_FILENAME%,'^ \*(.+?)[\_-]+(.+?) \*$','$1---$2')**  
_Guessing pattern:_ **%TRACK%---%TITLE%**  
End Action Group **Test 2011#20110112.Guess** (1 Action)

 

.. and this too ...

 Begin Action Group **Test 2011#20110112.Guess.2** 

Action #1  
_Actiontype 7:_ **Import tag fields (guess values)**  
_Source format:_ **$num(%\_FILENAME%,1)---$trimLeft(%_FILENAME%,'0123456789 -_')**  
_Guessing pattern:_ **%TRACK%---%TITLE%**  
End Action Group **Test 2011#20110112.Guess.2** (1 Action)

 

.. and this too ...

 Begin Action Group **Test 2011#20110112.FormatValue** 

Action #1  
_Actiontype 5:_ **Format value**  
_Field:_ **TRACK**  
_Formatstring:_ **$num(%\_FILENAME%,1)**

 

Action #2  
_Actiontype 5:_ **Format value**  
_Field:_ **TITLE**  
_Formatstring:_ **$trimLeft(%_FILENAME%,'0123456789 -_')**  
End Action Group **Test 2011#20110112.FormatValue** (2 Actions)

 

DD.20110112.1030.CET  
Edit.DD.20110112.1915.CET

---

<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 9, 2026, 12:22pm UTC](https://community.mp3tag.de/t/how-to-skip-whitespace-when-extracting-tags-from-filenames/11430/4 "2026-02-09T12:22:49Z")

</div>


