# How to Replace Illegal Characters Upon Writing Tags to Filename

**URL:** https://community.mp3tag.de/t/how-to-replace-illegal-characters-upon-writing-tags-to-filename/16397
**Category:** Support
**Created:** [December 9, 2014, 12:28pm UTC](https://community.mp3tag.de/t/how-to-replace-illegal-characters-upon-writing-tags-to-filename/16397 "2014-12-09T12:28:14Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![ragtag](https://community.mp3tag.de/user_avatar/community.mp3tag.de/ragtag/32/13146_2.png) [@ragtag](https://community.mp3tag.de/u/ragtag)
#### Post date: [December 9, 2014, 12:28pm UTC](https://community.mp3tag.de/t/how-to-replace-illegal-characters-upon-writing-tags-to-filename/16397/1 "2014-12-09T12:28:14Z")

</div>

Hi Everybody,

I have scoured the Mp3tag Scripting Functions, but cannot get this right: I want to replace the "illegal" Windows characters such as (:, ", ?, /, \*, |) and so forth, with any character of my own choosing, not just blank spaces. Can someone please help me with a script do just that? Also, how do I set it up so that **every time** Mp3tag writes the tag to filename, the illegal characters are replaced with my own?

Thanks for your assistance.

PS. I want to retain the "illegal" characters in the metadata.

---

<div class="post-metadata">

### Author: ![stanman](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/s/c5a1d2/32.png) [@stanman](https://community.mp3tag.de/u/stanman)
#### Post date: [December 9, 2014, 2:09pm UTC](https://community.mp3tag.de/t/how-to-replace-illegal-characters-upon-writing-tags-to-filename/16397/2 "2014-12-09T14:09:07Z")

</div>

Look [here](https://docs.mp3tag.de/scripting/#string-functions) under "Remove invalid characters from file name/file paths".

In Mp3tag go to Convert \> Tag - Filename and use the $validate command in the format string.

---

<div class="post-metadata">

### Author: ![ragtag](https://community.mp3tag.de/user_avatar/community.mp3tag.de/ragtag/32/13146_2.png) [@ragtag](https://community.mp3tag.de/u/ragtag)
#### Post date: [December 9, 2014, 2:41pm UTC](https://community.mp3tag.de/t/how-to-replace-illegal-characters-upon-writing-tags-to-filename/16397/3 "2014-12-09T14:41:35Z")

</div>

Thanks, I saw that, but did not know how to apply it.

On second look, I've got it. 🙂

---

<div class="post-metadata">

### Author: ![stanman](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/s/c5a1d2/32.png) [@stanman](https://community.mp3tag.de/u/stanman)
#### Post date: [December 9, 2014, 2:45pm UTC](https://community.mp3tag.de/t/how-to-replace-illegal-characters-upon-writing-tags-to-filename/16397/4 "2014-12-09T14:45:17Z")

</div>

This is the one I use $validate(%artist% - %track% - %title%,\_)

It replaces invalid characters with an underscore \_.

Edit: Ok, I just saw your edit.

---

<div class="post-metadata">

### Author: ![ragtag](https://community.mp3tag.de/user_avatar/community.mp3tag.de/ragtag/32/13146_2.png) [@ragtag](https://community.mp3tag.de/u/ragtag)
#### Post date: [December 9, 2014, 2:49pm UTC](https://community.mp3tag.de/t/how-to-replace-illegal-characters-upon-writing-tags-to-filename/16397/5 "2014-12-09T14:49:26Z")

</div>

Thanks again, stanman. I have to learn to read more carefully. Sorry for the bother.

Command: $replace(string,from,to) or $replace(string,from1,to1,from2,to2,...)  
Example: $replace(%artist% - %album% - %track% - %title%,\_,-)  
This example replaces all underscores with dashes. _You can provide additional pairs of from/to as parameters._

---

<div class="post-metadata">

### Author: ![Hg201](https://community.mp3tag.de/user_avatar/community.mp3tag.de/hg201/32/7797_2.png) [@Hg201](https://community.mp3tag.de/u/Hg201)
#### Post date: [June 29, 2022, 1:34am UTC](https://community.mp3tag.de/t/how-to-replace-illegal-characters-upon-writing-tags-to-filename/16397/6 "2022-06-29T01:34:11Z")

</div>

This is what I use:

```auto
$replace(%title%,",”,<,«,>,»,:,﹕,/,／,\,＼,|,¦,?,？,*,¤)

```

Enjoy!

---

<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: [July 29, 2022, 1:34am UTC](https://community.mp3tag.de/t/how-to-replace-illegal-characters-upon-writing-tags-to-filename/16397/7 "2022-07-29T01:34:14Z")

</div>

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