# Delete All But 1st Of An instance

**URL:** https://community.mp3tag.de/t/delete-all-but-1st-of-an-instance/9369
**Category:** Support
**Created:** [November 18, 2009, 11:15pm UTC](https://community.mp3tag.de/t/delete-all-but-1st-of-an-instance/9369 "2009-11-18T23:15:47Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![juggernaut](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/j/d07c76/32.png) [@juggernaut](https://community.mp3tag.de/u/juggernaut)
#### Post date: [November 18, 2009, 11:15pm UTC](https://community.mp3tag.de/t/delete-all-but-1st-of-an-instance/9369/1 "2009-11-18T23:15:47Z")

</div>

I'm wondering how to to delete all of a specific character using regex but the 1st one in the name. For example I wish to remove all - characters except the 1st one. Or I want to remove all . characters except the first one (and of course would have to add in the condition not to remove from the file extension).

---

<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: [November 19, 2009, 6:50am UTC](https://community.mp3tag.de/t/delete-all-but-1st-of-an-instance/9369/2 "2009-11-19T06:50:20Z")

</div>

> [@juggernaut](#):
>
> ... I'm wondering how to to delete all of a specific character using regex but the 1st one in the name. For example I wish to remove all - characters except the 1st one. ...

This is not a "regular" but a "standard scripting language" expression, which removes hyphens from the filename except the first hyphen from the left side (apply it as one line).

**$left(%\_filename%,$strchr(%\_filename%,'-'))** 

**$replace($mid(%\_filename%,$add($strchr(%\_filename%,'-'),1),$len(%\_filename%)),'-',)**

 

DD.20091119.0850.CET

---

<div class="post-metadata">

### Author: ![MatthiasM](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/m/bbe5ce/32.png) [@MatthiasM](https://community.mp3tag.de/u/MatthiasM)
#### Post date: [November 19, 2009, 7:59am UTC](https://community.mp3tag.de/t/delete-all-but-1st-of-an-instance/9369/3 "2009-11-19T07:59:17Z")

</div>

I'm not sure if I completely understand what you want,  
but I try to give a resolution for how I understood your question:

```
$regexp(%_FILENAME%,'(-)+',$1)

```

this replaces several successive '-' and keeps one .  
E.g. "This----or that----" will be "This-or that-" afterwards.

(BTW: %\_FILENAME% is always the name _without_ the extension; to also replace it in the extension, you would have to use %FILENAME\_EXT% instead)

If you want to replace other characters, put it in the above bracket.  
To replace special characters, like the dot '.' (which have special meanings in regular expressions) you have to preceed them with a '':

```
$regexp(%_FILENAME%,'(\.)+',$1)

```

This replaces several '.' with one '.'

(you can also replace more than one character at once:

```
$regexp(%_FILENAME%,'([-_\.])+',$1)

```

replaces multiple successive '-', '\_' and '.' characters with the corresponding single character.  
e.g. "This\_\_is--My...Special....File---name" will be "This\_is-My.Special.File-name"

Is this what you try to do?

with regards,  
Matthias

---

<div class="post-metadata">

### Author: ![juggernaut](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/j/d07c76/32.png) [@juggernaut](https://community.mp3tag.de/u/juggernaut)
#### Post date: [November 19, 2009, 10:09am UTC](https://community.mp3tag.de/t/delete-all-but-1st-of-an-instance/9369/4 "2009-11-19T10:09:28Z")

</div>

> [@](#):
>
> BTW: %\_FILENAME% is always the name without the extension; to also replace it in the extension, you would have to use %FILENAME\_EXT% instead

Ah that makes sense now.

@DetlevD

Thanks a lot that worked. I have only been using regular expressions up to now so I'm going to have to look into how those functions work.

---

<div class="post-metadata">

### Author: ![juggernaut](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/j/d07c76/32.png) [@juggernaut](https://community.mp3tag.de/u/juggernaut)
#### Post date: [November 19, 2009, 11:55am UTC](https://community.mp3tag.de/t/delete-all-but-1st-of-an-instance/9369/5 "2009-11-19T11:55:08Z")

</div>

I looked up some stuff on Lookbehind to try and do this alternatively with regex but the syntax does not seem to be correct. It doesn't look like mp3tag supports it.

---

<div class="post-metadata">

### Author: ![dano](https://community.mp3tag.de/user_avatar/community.mp3tag.de/dano/32/6_2.png) [@dano](https://community.mp3tag.de/u/dano)
#### Post date: [November 19, 2009, 12:18pm UTC](https://community.mp3tag.de/t/delete-all-but-1st-of-an-instance/9369/6 "2009-11-19T12:18:36Z")

</div>

It's supported with fixed length.

---

<div class="post-metadata">

### Author: ![juggernaut](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/j/d07c76/32.png) [@juggernaut](https://community.mp3tag.de/u/juggernaut)
#### Post date: [November 19, 2009, 12:22pm UTC](https://community.mp3tag.de/t/delete-all-but-1st-of-an-instance/9369/7 "2009-11-19T12:22:54Z")

</div>

Ah. Well fixed length wont be any use in this case.

---

<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:21pm UTC](https://community.mp3tag.de/t/delete-all-but-1st-of-an-instance/9369/8 "2026-02-09T12:21:57Z")

</div>


