Regex based on last appearance of -

Post any Bulk Rename Utility support requirements here. Open to all registered users.

Regex based on last appearance of -

Postby Tanjamuse » Mon May 22, 2017 4:35 pm

Hello.

I hope I'm posting this in the right place.

Is it possible to base a Regex on the last occurrence of - instead of the first?

I have this based on the first one, but I lack the knowledge of how to change it to the last.

Match: (.+?)(- .+)
Replace: \2

This is an example of file-names:

A Christmas Carol_ Hetalia - Axis Powers - CanadasOpposite - A Hetalia Christmas Carol

I would like it changed to

CanadasOpposite - A Hetalia Christmas Carol

But I have other files in the same folder which also needs batch name like the following

A Christmas Story - BlackFireDragonStar - Merry Christmas Hotel Transylvania_

That only needs the first bit deleted like:

BlackFireDragonStar - Merry Christmas Hotel Transylvania_

which is why the first Regex doesn't quite work and I'm looking for something able to read from right to left instead.

I hope this all made sense and thanks in advance for the help.
Tanjamuse
 
Posts: 2
Joined: Mon May 22, 2017 4:24 pm

Re: Regex based on last appearance of -

Postby Emerkamp » Mon May 22, 2017 5:20 pm

Hi, I would do last first. This should leave the first untouched for now.

But I have other files in the same folder which also needs batch name like the following

A Christmas Story - BlackFireDragonStar - Merry Christmas Hotel Transylvania_

That only needs the first bit deleted like:

BlackFireDragonStar - Merry Christmas Hotel Transylvania_


Match= (.*) - (.*) - (.*)(_)
Rep=\2 - \3\4


Then The First
A Christmas Carol_ Hetalia - Axis Powers - CanadasOpposite - A Hetalia Christmas Carol

I would like it changed to

CanadasOpposite - A Hetalia Christmas Carol


Match=(.*) - (.*) - (.*)
Rep=\2 - \1

You can be more picky here and change first (.) to this (.)(_)(.) if you have an underscore always.
Test this first because I haven't, but the logic should be right
Last edited by Emerkamp on Mon May 22, 2017 6:44 pm, edited 1 time in total.
Emerkamp
 
Posts: 88
Joined: Sat Aug 23, 2014 2:35 pm

Re: Regex based on last appearance of -

Postby Tanjamuse » Mon May 22, 2017 6:02 pm

Can someone confirm that the following would do what I want before I begin to do 50.000+

As far as I can tell it should work on both the combinations.

A Christmas Carol_ Hetalia - Axis Powers - CanadasOpposite - A Hetalia Christmas Carol => CanadasOpposite - A Hetalia Christmas Carol

and

A Christmas Story - BlackFireDragonStar - Merry Christmas Hotel Transylvania_

Match (.*) - (.*) - (.*)
Replace \2 - \3
Tanjamuse
 
Posts: 2
Joined: Mon May 22, 2017 4:24 pm

Re: Regex based on last appearance of -

Postby Emerkamp » Mon May 22, 2017 6:40 pm

Hi, Yea sorry. I forgot The *

Easy way to test it, is to make a text filename list (BRU Right click contex menu) and paste it into notepad++.
Then try your regex code out with it's replace function.
Without seeing all your files, we are kinda quessing. It looks good to me.
Emerkamp
 
Posts: 88
Joined: Sat Aug 23, 2014 2:35 pm


Return to BRU Support