Rearrange with multiple occurrence of the separator

A swapping-ground for Regular Expression syntax

Rearrange with multiple occurrence of the separator

Postby Tiller » Wed Aug 20, 2014 9:17 pm

Trying to rearrange filename string with multiple occurrences of the separator

Hi, i am totally stuck and my brain hurts :(

WeightWatchers-115-1-0
Taster talent potions_Normal-294-1-1
Junk Dismantling-85-0-2
Intro logo removal-150-1-3
Icons for the new items of patch 2_0 mod-226-1-0
HDR hotfix -331-v1-3-5
AA and visual enhancer-331-v1-3

Above are the copies of a few of the files I am trying to rename. I want to swap all the characters up to the first "-" with the characters after it e.g

WeightWatchers-115-1-0 ---> 115-1-0-WeightWatchers

Taster talent potions_Normal-294-1-1 ---> 294-1-1-Taster talent potions_Normal

Junk Dismantling-85-0-2 ---> 85-0-2-Junk Dismantling


I tried using the below expression, but they rename incorrectly.

RegEx(1)
Match: (.*)(-)(.*)
Replace: \1-\3

I will continue reading but i am hoping for someone to help prod me in the right direction.

Thanks
Tiller

edited for clarity

Edit 2

Okay i missed the post before me, lol. I neeed sleeep...

GMA wrote:Hi, mrvelous01:
This is what you need:

1. Set RegEx (1) as:
MATCH: (.*?)-(.*)
REPLACE: \2 - \1

2. In the Remove (5) field, check "Trim" (that'll remove any spaces left at the beginning of the file name).

3. Use the preview to see if everything's OK, and then press "Rename".

One thing; if there's no space before/after the hyphen (e.g.: "Title-Artist") it will be added as a result of the renaming process (e.g.: "Artist - Title"), which may or may not be a problem for you. If that IS a problem, then you're gonna have to use two different RegExs.
Cheers,

Gabriel.

Seems to have the right way to do it, now I need to find out why it worked :?
Tiller
 
Posts: 1
Joined: Wed Aug 20, 2014 8:42 pm

Re: Rearrange with multiple occurrence of the separator

Postby Stefan » Thu Aug 21, 2014 6:14 am

 

Tiller wrote:I want to swap all the characters up to the first "-" with...


Okay i missed the post before me,
Seems to have the right way to do it, now I need to find out why it worked :?



The trick is the '?' question mark. Goggle for 'regex greedy'




 
Stefan
 
Posts: 736
Joined: Fri Mar 11, 2005 7:46 pm
Location: Germany, EU


Return to Regular Expressions