# Regexp not working as expected in convert --\> tag - filename ?

**URL:** <https://community.mp3tag.de/t/regexp-not-working-as-expected-in-convert-tag-filename/17454>\
**Category:** Support\
**Created:** [December 12, 2015, 10:50pm UTC](https://community.mp3tag.de/t/regexp-not-working-as-expected-in-convert-tag-filename/17454 "2015-12-12T22:50:08Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![smlova](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/s/df788c/32.png) [@smlova](https://community.mp3tag.de/u/smlova)\
**Post date:** [December 12, 2015, 10:50pm UTC](https://community.mp3tag.de/t/regexp-not-working-as-expected-in-convert-tag-filename/17454/1 "2015-12-12T22:50:08Z")

</div>

I am trying to relocate a bunch of mostly untagged/unmatched tracks in a given folder using convert --\> tag - filename ..

My format string is:  
e:\path$if2(%artist%,'unknown-artist')$if2(%album%,'unknown-album')$if2(%title%,$regexp(%\_filename%,^\s\*[0-9]_\s_-_\s_[0-9]_\s_) )

The logic being to remove leading spaces, digits and dashes in front of the filename, and use that as the track's filename ..

Generally, I have been reading the regexp topics .. eg: [/t/521/1](https://community.mp3tag.de/t/521/1)

But it seems that not all regexps acceptable in an action are available for use in the $regexp function in specifying format strings .. because most would give REGEXP error in the preview window ..

I have unsuccessfully tried quite a few different ways at specifying a valid regexp to do this .. and almost always running into regexp errors ..

I suspect I am missing something obvious, or working blindside of commonly known issues with using this section ..

Please, can anyone help point me in the right direction ..

Thanks in advance

---

<div class="post-metadata">

**Author:** ![smlova](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/s/df788c/32.png) [@smlova](https://community.mp3tag.de/u/smlova)\
**Post date:** [December 12, 2015, 11:05pm UTC](https://community.mp3tag.de/t/regexp-not-working-as-expected-in-convert-tag-filename/17454/2 "2015-12-12T23:05:55Z")

</div>

Just wanted to point out that I do realize I have no replacement for the matched string in that format string ..

The reason for that is that it is not obvious to me how to specify NULL as replacement .. and I already tried using ( ) to select a sub-match, and then using $1 to apply the sub-match as replacement .. and I was getting regexp error ..

So, I would appreciate an example on how to specify NULL as a replacement value .. and or how to apply sub-matches as replacement

---

<div class="post-metadata">

**Author:** ![ryerman](https://community.mp3tag.de/user_avatar/community.mp3tag.de/ryerman/32/5285_2.png) [@ryerman](https://community.mp3tag.de/u/ryerman)\
**Post date:** [December 13, 2015, 2:02am UTC](https://community.mp3tag.de/t/regexp-not-working-as-expected-in-convert-tag-filename/17454/3 "2015-12-13T02:02:09Z")

</div>

Try this:

```
$regexp(%_filename%,'^[\d\s-]+',)

```

The single quotes escape characters that have special meaning in Mp3tag eg. []  
Specify NULL by not entering anything after the last comma.

---

<div class="post-metadata">

**Author:** ![smlova](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/s/df788c/32.png) [@smlova](https://community.mp3tag.de/u/smlova)\
**Post date:** [December 13, 2015, 10:10am UTC](https://community.mp3tag.de/t/regexp-not-working-as-expected-in-convert-tag-filename/17454/4 "2015-12-13T10:10:41Z")

</div>

Awesome .. thanks a million ..

I knew it had to be something 'obvious' like that .. more than incorrect regexp

That certainly works great .. with character sets or not .. I tried character sets first because they are so much more legible and short ..

---

<div class="post-metadata">

**Author:** ![smlova](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/s/df788c/32.png) [@smlova](https://community.mp3tag.de/u/smlova)\
**Post date:** [December 13, 2015, 10:29am UTC](https://community.mp3tag.de/t/regexp-not-working-as-expected-in-convert-tag-filename/17454/5 "2015-12-13T10:29:21Z")

</div>

Another question .. pertains to use of absolute paths ..

How do I specify a starting absolute path for the conversion?

I started my format string with e:\dir\dir .. but instead of actually using the absolute path, mp3tag created these path elements under the folder where the songs to be renamed where .. like:  
e  
!-- dir

```
!-- dir 

```

It would seem obvious that using placeholders like %\_parent\_directory%, %\_directory%, etc is the way to go .. but my previous attempt at using those yielded incorrect results due to the different levels of nesting of the individual tracks ..

Any suggestions would be appreciated ..

---

<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:** [December 13, 2015, 10:41am UTC](https://community.mp3tag.de/t/regexp-not-working-as-expected-in-convert-tag-filename/17454/6 "2015-12-13T10:41:33Z")

</div>

> [@smlova](#):
>
> ... How do I specify a starting absolute path for the conversion? ...

Please be more closely, which action or converter is involved, show a practical example.

DD.20151213.1241.CET

---

<div class="post-metadata">

**Author:** ![smlova](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/s/df788c/32.png) [@smlova](https://community.mp3tag.de/u/smlova)\
**Post date:** [December 13, 2015, 12:59pm UTC](https://community.mp3tag.de/t/regexp-not-working-as-expected-in-convert-tag-filename/17454/7 "2015-12-13T12:59:58Z")

</div>

> [@DetlevD](#):
>
> Please be more closely, which action or converter is involved, show a practical example.

This is a continuation of my initial post in this topic .. I am doing Convert --\> tag - filename

And in the format string, I have used:  
e:\dir\dir$if2(%artist%,'unknown-artist')$if2(%album%,'unknown-album')$if2(%title%,$regexp(%\_filename%,'^\s\*[0-9]_\s_-_\s_[0-9]_\s_',) )

The preview seemed to suggest it would work and the files will be written at the correct absolute path .. but that did'nt happen. Instead the files were written with respect to the current top directory where the tracks being renamed reside.

---

<div class="post-metadata">

**Author:** ![ryerman](https://community.mp3tag.de/user_avatar/community.mp3tag.de/ryerman/32/5285_2.png) [@ryerman](https://community.mp3tag.de/u/ryerman)\
**Post date:** [December 13, 2015, 3:34pm UTC](https://community.mp3tag.de/t/regexp-not-working-as-expected-in-convert-tag-filename/17454/8 "2015-12-13T15:34:51Z")

</div>

Here's a format string template for Tag to Filename conversion.  
It will move files to a folder below the directory in which they currently exist.

```
%_folderpath%Some Folder\Another Folder\\%_filename%

```

%\_folderpath% includes a trailing backslash.  
New folders are created as necessary.

---

<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:** [December 13, 2015, 3:44pm UTC](https://community.mp3tag.de/t/regexp-not-working-as-expected-in-convert-tag-filename/17454/9 "2015-12-13T15:44:34Z")

</div>

> [@smlova](#):
>
> ... I am doing Convert --\> tag - filename  
> And in the format string, I have used:  
> e:\dir\dir$if2(%artist%,'unknown-artist')$if2(%album%,'unknown-album')$if2(%title%,$regexp(%\_filename%,'^\s\*[0-9]_\s_-_\s_[0-9]_\s_',) )  
> The preview seemed to suggest it would work and the files will be written at the correct absolute path .. but that did'nt happen. Instead the files were written with respect to the current top directory where the tracks being renamed reside.

Against a media file, having ARTIST, ALBUM, TITLE filled with correct values, this formatstring has been applied in converter "Tag-Filename" and Mp3tag has done it as expected.

**'e:\dir\dir\'$if2(%ARTIST%,'unknown-artist')'\'$if2(%ALBUM%,'unknown-album')'\'$if2(%TITLE%,$regexp(%\_filename%,'^[\d\s-]\*',)' ')**

The formatstring moved the selected media file into a subfolder tree on drive E, for example ...  
"T:\TEST\Testalbum\123 - Testfile.mp3" -\>  
"e:\dir\dir\Kinobe\Soundphiles\Bopalong.mp3"

Against a media file, having set _no_ tagfields ARTIST, ALBUM, TITLE, the formatstring has been applied in converter "Tag-Filename" and Mp3tag has done it as expected.

The formatstring moved the selected media file into a subfolder tree on drive E, for example ...  
"T:\TEST\Testalbum\123 - Testfile.mp3" -\>  
"e:\dir\dir\unknown-artist\unknown-album\Testfile .mp3"

Even the filename with the trailing space has been created as designed in the formatstring.

DD.20151213.1805.CET

---

<div class="post-metadata">

**Author:** ![smlova](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/s/df788c/32.png) [@smlova](https://community.mp3tag.de/u/smlova)\
**Post date:** [December 19, 2015, 8:00pm UTC](https://community.mp3tag.de/t/regexp-not-working-as-expected-in-convert-tag-filename/17454/10 "2015-12-19T20:00:23Z")

</div>

> [@DetlevD](#):
>
> Against a media file, having ARTIST, ALBUM, TITLE filled with correct values, this formatstring has been applied in converter "Tag-Filename" and Mp3tag has done it as expected.
> 
> **'e:\dir\dir\'$if2(%ARTIST%,'unknown-artist')'\'$if2(%ALBUM%,'unknown-album')'\'$if2(%TITLE%,$regexp(%\_filename%,'^[\d\s-]\*',)' ')**
> 
> The formatstring moved the selected media file into a subfolder tree on drive E, for example ...  
> "T:\TEST\Testalbum\123 - Testfile.mp3" -\>  
> "e:\dir\dir\Kinobe\Soundphiles\Bopalong.mp3"

Sorry, been late in getting back to this .. been travelling ..

Yes, I see the solution in your post, DetlevD .. thanks .. literal directory specification in the format string need to be quoted in single quotes .. just like the regexp ..

Thanks to all who responded for all the suggestions and responses .. I have improved my understanding of how mp3tag works ..

---

<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:26pm UTC](https://community.mp3tag.de/t/regexp-not-working-as-expected-in-convert-tag-filename/17454/11 "2026-02-09T12:26:00Z")

</div>


