# regex to take the first, last and middle separated by "-"

**URL:** https://community.mp3tag.de/t/regex-to-take-the-first-last-and-middle-separated-by/12171
**Category:** Support
**Created:** [June 19, 2011, 9:28am UTC](https://community.mp3tag.de/t/regex-to-take-the-first-last-and-middle-separated-by/12171 "2011-06-19T09:28:59Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![msdobrescu](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/m/22d042/32.png) [@msdobrescu](https://community.mp3tag.de/u/msdobrescu)
#### Post date: [June 19, 2011, 9:28am UTC](https://community.mp3tag.de/t/regex-to-take-the-first-last-and-middle-separated-by/12171/1 "2011-06-19T09:28:59Z")

</div>

Hello,

I have a huge collection in form:

- -   
or  
 - - -

I would need to transform these in:

\<year\> -   
\<year\> - ()

using one regex expression (it is really hard to select the right folders of thoscategories one by one, as they are many).

First, I would have been happy to have - at least - the form:

\<year\> - -

but I couldn't create a regex to take the first expression before the first "-".

It seems that lazy/non-greedy "?" expression doesn't work.

What is the solution, the right expression for these?

Thank you,  
Mike

---

<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: [June 19, 2011, 1:11pm UTC](https://community.mp3tag.de/t/regex-to-take-the-first-last-and-middle-separated-by/12171/2 "2011-06-19T13:11:32Z")

</div>

> [@mihai](#):
>
> - -   
> or  
> - - -   
> ...
> 
> \<year\> -   
> \<year\> - ()  
> ...
> 
> \<year\> - -

Hi Mike,  
do you really use V2.36? I am not quite sure whether my advice is valid for that version, as the current version is 2.49.

Coming to your questions: If you try to rename files then the converter Tag - Filename or Filename - Filename would be suitable. Or an action. Why a regular expression?  
You do not have to apply the conversion one by one if you filter your tracks first.  
e.g. if you have

- - -   
then the filter would be:  
%\_filename% MATCHES ._-._-._-._  
With the converter filename - filename and the pattern  
%1 - %2 - %3 - %4  
and the output pattern  
%1\%4 - %3 (%2)  
you get it.  
But, looking at your output examples, you do not seem to be sure what to do with the "extra" you have to find the right pattern.

BTW: why don't you simply apply the converter Tag - Filename in a brute force action.  
If you know what the "extra" is, you could use the square brackets to include optional data:  
%artist%\%year% - %album%[()]  
Or don't you have the data stored in your tags? The I would seriously think about importing that first.

---

<div class="post-metadata">

### Author: ![msdobrescu](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/m/22d042/32.png) [@msdobrescu](https://community.mp3tag.de/u/msdobrescu)
#### Post date: [June 20, 2011, 6:46am UTC](https://community.mp3tag.de/t/regex-to-take-the-first-last-and-middle-separated-by/12171/3 "2011-06-20T06:46:53Z")

</div>

> [@ohrenkino](#):
>
> Hi Mike,  
> do you really use V2.36? I am not quite sure whether my advice is valid for that version, as the current version is 2.49.
> 
> Coming to your questions: If you try to rename files then the converter Tag - Filename or Filename - Filename would be suitable. Or an action. Why a regular expression?  
> You do not have to apply the conversion one by one if you filter your tracks first.  
> e.g. if you have
> 
> - - -   
> then the filter would be:  
> %\_filename% MATCHES ._-._-._-._  
> With the converter filename - filename and the pattern  
> %1 - %2 - %3 - %4  
> and the output pattern  
> %1\%4 - %3 (%2)  
> you get it.  
> But, looking at your output examples, you do not seem to be sure what to do with the "extra" you have to find the right pattern.
> 
> BTW: why don't you simply apply the converter Tag - Filename in a brute force action.  
> If you know what the "extra" is, you could use the square brackets to include optional data:  
> %artist%\%year% - %album%[()]  
> Or don't you have the data stored in your tags? The I would seriously think about importing that first.

Hi,

Regarding the version, it must have been set at the first registering.

Not all the files have tags, I have 2 cases I need to handle through one expression (see, " - " is some data, almost never the same, so I can't make a clear pattern) because there are about 128 gigs of mp3s with many albums coming in some of the 2 forms explained.

I've already managed to have one expression to catch the two patterns, but mp3tag says it converts 0 of 2344 cases, although it makes the changes properly. This confused me  
What I couldn't do is the replacement when "extra" stuff is missing.  
I get "()" in the result, but I could do a proper rename by looking for and removing the "()".

I actually move the files on a pattern like -\> \<artist\sound\mp3\year - album\>.

Mp3Tag is great, although I would prefer a GPL one like puddletag (which claims to be a clone of Mp3Tag) and I plan to move to linux entirely. I do prefer the approach of EasyTag as GUI also.

Thank you.

---

<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:23pm UTC](https://community.mp3tag.de/t/regex-to-take-the-first-last-and-middle-separated-by/12171/4 "2026-02-09T12:23:10Z")

</div>


