Page 1 of 1

Regex based on last appearance of -

PostPosted: Mon May 22, 2017 4:35 pm
by Tanjamuse
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.

Re: Regex based on last appearance of -

PostPosted: Mon May 22, 2017 5:20 pm
by Emerkamp
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

Re: Regex based on last appearance of -

PostPosted: Mon May 22, 2017 6:02 pm
by Tanjamuse
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

Re: Regex based on last appearance of -

PostPosted: Mon May 22, 2017 6:40 pm
by Emerkamp
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.