# Example to remove track number from TITLE via Regexp

**URL:** https://community.mp3tag.de/t/example-to-remove-track-number-from-title-via-regexp/53356
**Category:** General Discussion
**Created:** [May 26, 2021, 4:21pm UTC](https://community.mp3tag.de/t/example-to-remove-track-number-from-title-via-regexp/53356 "2021-05-26T16:21:40Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Chris](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/c/958977/32.png) [@Chris](https://community.mp3tag.de/u/Chris)
#### Post date: [May 26, 2021, 4:21pm UTC](https://community.mp3tag.de/t/example-to-remove-track-number-from-title-via-regexp/53356/1 "2021-05-26T16:21:40Z")

</div>

I use a variant of the logic in areve's post from many years back. It strips errant leading track numbers from title tags when I rename the files based on tag info, because I have a specific filename format requirement.

The reason for this was I had a batch of files where the encoding template had incorrectly added a leading whitespace and track numbers to the titles, separated from the actual title with a "." (period/full stop/dot), so this regex in the rename rule fixed it.

It would also work for a tags-from-filename scenario...

Given a file with the following info:  
"`beatles-pepper-05.flac`"

`%album%`: Sgt. Pepper's Lonely Hearts Club Band  
`%artist%`: The Beatles  
`%catalogid%`: PCS 7027  
`%track%`: 05. Fixing A Hole

`%album% $if2(%catalogid% ,"")- $num(%track%,2) -- %artist% - $regexp(%title%,(\s?\d{1,2}\.\s),)`

This would rename the file to:  
`Sgt. Pepper's Lonely Hearts Club Band PCS 7027 - 05 -- The Beatles - Fixing A Hole.flac`

The $regexp logic looks first for an optional whitespace character, then matches between 1 and 2 digits (as some tracks were not tagged with track numbers including a leading zero) then a full stop/period, then another whitespace.

That means %track% is simply rewritten to "Fixing A Hole". However it would also match " 5. Fixing A Hole", " 05. Fixing A Hole", "05. Fixing A Hole" etc.

As always, regexr is useful for live explanations of tags and so on. Above example with some sample data: [regexr.com/5tov4](http://regexr.com/5tov4)

---

<div class="post-metadata">

### Author: ![Florian](https://community.mp3tag.de/user_avatar/community.mp3tag.de/florian/32/5759_2.png) [@Florian](https://community.mp3tag.de/u/Florian)
#### Post date: [May 28, 2021, 9:08am UTC](https://community.mp3tag.de/t/example-to-remove-track-number-from-title-via-regexp/53356/2 "2021-05-28T09:08:31Z")

</div>

Hi and welcome!

Thanks for your example — I've moved this to a separate topic as I'm still trying to keep the [Regular Expressions](https://community.mp3tag.de/t/regular-expressions/521) topic somewhat general. Your example is more of an application of [areve's regular expressions to remove track numbers](https://community.mp3tag.de/t/regular-expressions/521/3) and [How to remove/trim leading track numbers?](https://community.mp3tag.de/t/actions-and-batch-operations/967/11) from the FAQ.

I've also noticed that you're mixing `%track%` and `%title%` in your example — you probably mean `%title%`.

---

<div class="post-metadata">

### Author: ![Florian](https://community.mp3tag.de/user_avatar/community.mp3tag.de/florian/32/5759_2.png) [@Florian](https://community.mp3tag.de/u/Florian)
#### Post date: [April 4, 2022, 9:03pm UTC](https://community.mp3tag.de/t/example-to-remove-track-number-from-title-via-regexp/53356/3 "2022-04-04T21:03:40Z")

</div>


