# Insert text with a regular expression in the filename

**URL:** <https://community.mp3tag.de/t/insert-text-with-a-regular-expression-in-the-filename/60079>\
**Category:** Support\
**Created:** [February 15, 2023, 4:31pm UTC](https://community.mp3tag.de/t/insert-text-with-a-regular-expression-in-the-filename/60079 "2023-02-15T16:31:29Z")\
**Posts on this page:** 4\
**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:** [February 15, 2023, 4:31pm UTC](https://community.mp3tag.de/t/insert-text-with-a-regular-expression-in-the-filename/60079/1 "2023-02-15T16:31:29Z")

</div>

@ohrenkino:

Your filter did find the matches, perfectly. I then tried to apply what I have learned from your example, to try to add a _dash_ after the **first digit** in the track number, located at the beginning of the file name. I used Action \> "Replace with regular expression" for the renumbering, like this:

**Field: \_FILENAME**

**Regular expression: ^\d** (tried this with and without parenthesis)

**Replace matches with: d-** (and various other combinations such as for e.g. ^\d-)(The first digit was correctly located, but was not correctly replaced with the correct number and the dash?)

The first digit was replaced and followed by the dash, all right, but with the letter "d" instead of the correct retained number. What am I doing wrong?

---

<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:** [February 15, 2023, 4:37pm UTC](https://community.mp3tag.de/t/insert-text-with-a-regular-expression-in-the-filename/60079/2 "2023-02-15T16:37:12Z")

</div>

> [@ragtag](#):
>
> **Regular expression: ^\d**

If you want to keep the number, then you have to tell MP3tag that it should remember it - which is done by enclosing the pattern in parenthesis.  
So for something like  
101. My music file  
which should become  
1-01. My music file  
Try:  
Search pattern: `^(\d)(.*)`  
Replace string: `$1-$2`

Further information about regular expressions can be found in the documentation:

> **[Regular Expressions – Mp3tag Documentation](https://docs.mp3tag.de/regex/)**
>
> Documentation on support for regular expressions in Mp3tag. Mp3tag is the universal Tag Editor.

---

<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:** [February 15, 2023, 4:55pm UTC](https://community.mp3tag.de/t/insert-text-with-a-regular-expression-in-the-filename/60079/3 "2023-02-15T16:55:10Z")

</div>

Thank you, it did the job splendidly.

---

<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:** [March 17, 2023, 4:38pm UTC](https://community.mp3tag.de/t/insert-text-with-a-regular-expression-in-the-filename/60079/4 "2023-03-17T16:38:07Z")

</div>

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