# Set Track = last 2 characters Filename

**URL:** https://community.mp3tag.de/t/set-track-last-2-characters-filename/67226
**Category:** Support
**Created:** [January 21, 2025, 3:47pm UTC](https://community.mp3tag.de/t/set-track-last-2-characters-filename/67226 "2025-01-21T15:47:59Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![coyote](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/c/d6d6ee/32.png) [@coyote](https://community.mp3tag.de/u/coyote)
#### Post date: [January 21, 2025, 3:47pm UTC](https://community.mp3tag.de/t/set-track-last-2-characters-filename/67226/1 "2025-01-21T15:47:59Z")

</div>

I want an Action that sets "Track" equal to the last 2 characters of Filename, please.

---

<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: [January 21, 2025, 3:53pm UTC](https://community.mp3tag.de/t/set-track-last-2-characters-filename/67226/2 "2025-01-21T15:53:19Z")

</div>

Try an action of the type "Format value" or Convert\>Tag-Tag for TRACK  
Format string: `$regexp(%_filename%,.*(..),$1)`

It could be that a more elegant solution would be possible. But without a real example this is the best I could think of.

---

<div class="post-metadata">

### Author: ![LyricsLover](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/l/c6cbf5/32.png) [@LyricsLover](https://community.mp3tag.de/u/LyricsLover)
#### Post date: [January 21, 2025, 4:01pm UTC](https://community.mp3tag.de/t/set-track-last-2-characters-filename/67226/3 "2025-01-21T16:01:56Z")

</div>

Beside the Action itself:  
Please be aware that most player except a number in TRACK, not any other random text.

Another attempt could be Convert Tag -\> Tag with  
`$right(%_FILENAME%,2)`

 ![image](https://community.mp3tag.de/uploads/default/original/3X/0/3/0322c245d32a66e0bbc494a31717b9afc9ce354a.png)

This will replace whatever content currently exists in `TRACK` with the last 2 characters from the filename.

From the help-[documentation](https://docs.mp3tag.de/scripting/#string-functions):

> `$right(x,n)` returns the rightmost n characters of text x.

---

<div class="post-metadata">

### Author: ![coyote](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/c/d6d6ee/32.png) [@coyote](https://community.mp3tag.de/u/coyote)
#### Post date: [January 21, 2025, 4:50pm UTC](https://community.mp3tag.de/t/set-track-last-2-characters-filename/67226/4 "2025-01-21T16:50:50Z")

</div>

Thank you very very much, ohrenkino and LyricsLover! I tested both solutions and both worked perfectly!

I deeply appreciate all the help with tag programming I've recieved from this community over the years, thanks for being one of the best places on the Internet!

---

<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 20, 2025, 4:51pm UTC](https://community.mp3tag.de/t/set-track-last-2-characters-filename/67226/5 "2025-02-20T16:51:41Z")

</div>

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