A simple field reversal (i thought) RegEx

A swapping-ground for Regular Expression syntax

A simple field reversal (i thought) RegEx

Postby Mattbru » Thu Apr 24, 2008 8:31 am

Hi all (& Jim),

I reckon I'm close after studying every example I could find on this site.

Have a file named

"v-Escape..., Over 2 Hours Of Pure Chillout (Disc 1)-08-05-Quanta Qualia-Patrick Hawes.mp3"

I want to swap the last 2 titles around (ie change the last part of this file from Quanta Qualia-Patrick Hawes
to Patrick Hawes-Quanta Qualia).

(Therefore the result should be "v-Escape..., Over 2 Hours Of Pure Chillout (Disc 1)-08-05-Patrick Hawes-Quanta Qualia.mp3")

For match, im using: (.+)(\s*-\s*)(.+)(\s*-\s*)(.+)(\s*-\s*)(.+)(\s*-\s*)(.+)(\s*-\s*)(.+)

In replace, im using: \1 - \3 - \5 - \7 - \11 - \9 (swapping fields 9 & 11, as "-" is field 10).

In the new name preview I am getting: \1 - \3 - \5 - \7 - \11 - \9.mp3 (in red)

Anyone want to put me out of my misery?

(Also, I am thinking that there must be a program that will let you generate the match details, using a gui environment, and then paste into BRU...)

Thanks
Matt
Mattbru
 
Posts: 2
Joined: Thu Apr 24, 2008 3:26 am

Re: A simple field reversal (i thought) RegEx

Postby Admin » Thu Apr 24, 2008 4:54 pm

I think you need to revise your RE> It hink the PCE engine that I use does funny things once you get beyond \10 as it doesn't know if \11 is \1 and 1 or \11. Try to get down to less than \9 if you can.

That is probably the issue.



Jim
Admin
Site Admin
 
Posts: 2343
Joined: Tue Mar 08, 2005 8:39 pm

Re: A simple field reversal (i thought) RegEx

Postby GMA » Fri Apr 25, 2008 5:24 pm

Hi, Mattbru:
Does the following expresion work for you? (I mean, is pretty simple because it relies purely on the dashes, but I don't know if all the files you want to rename share the same "dashes structure"):

MATCH = (.*)-(.*)-(.*)-(.*)-(.*)-(.*)
REPLACE = \1-\2-\3-\4-\6-\5

I know at least it'll change "v-Escape..., Over 2 Hours Of Pure Chillout (Disc 1)-08-05-Quanta Qualia-Patrick Hawes.mp3" to "v-Escape..., Over 2 Hours Of Pure Chillout (Disc 1)-08-05-Patrick Hawes-Quanta Qualia.mp3", as you wanted. If it doesn't work with the rest of your files, maybe you could give us a couple other file names so we can tell what's common between them.
Hope that helps. Best regards,

Gabriel.
GMA
 
Posts: 91
Joined: Sun Dec 02, 2007 1:30 pm
Location: Argentina

Re: A simple field reversal (i thought) RegEx

Postby Jane » Sun Apr 27, 2008 1:41 am

I found the following also worked. I don't think you need to capture each little chunk separately, as long as you do so with the parts you want to swap. This means the group numbers don't have to go above 3 - i.e. 1 group for all up to the swapped parts, and 1 group each for the parts you want to swap.
I did search:
(.*-)(\w+\s\w+)-(\w+\s\w+)

Replace with
\1\3-\2
This uses the greediness of .* to capture everything, then give up only what it needs to in order to match the final (\w+\s\w+)-(\w+\s\w+)
This works with the example given, but if the example is not typical it may not work on others.

Cordially,
Jane
Jane
 
Posts: 24
Joined: Sat Aug 05, 2006 1:20 am


Return to Regular Expressions