flipping names exchange swap move first last name, firstname

A swapping-ground for Regular Expression syntax

flipping names exchange swap move first last name, firstname

Postby lcastan » Sat Jun 25, 2011 6:27 am

I am very new at this. I looked at the examples in previous posts but couldn't get them to work for me.

I have files named like
FirstName LastName - songtitle.ext and I want to rename it
LastName, Firstname - songtitle.ext

How can I do this?
lcastan
 
Posts: 4
Joined: Sat Jun 25, 2011 6:23 am

flipping names exchange swap move first last name, firstname

Postby Stefan » Sat Jun 25, 2011 3:22 pm

FROM:
FirstName LastName - songtitle.ext
TO:
LastName, Firstname - songtitle.ext

DO:
RegEx(1)
Search: (.+) (.+)( - .+)
Replace: \2, \1\3



Note:
* test this first with copies of your real files!
* this solution will only work for names, build like the examples you have provided.
* select a few or all files in "Name"-column to see the preview in "NewName"-column.
* if all went fine, press at [Rename]

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

Re: fliping names

Postby lcastan » Sat Jun 25, 2011 10:33 pm

Stefan, You're life saver. Thanks.
It worked like a charm. :D
lcastan
 
Posts: 4
Joined: Sat Jun 25, 2011 6:23 am

Re: flipping names exchange swap move first last name, firstname

Postby BRUlvr100 » Sun Oct 16, 2011 4:51 am

I took a look at the solution above first, and found it didn't quite work. I have a similar problem as this poster, but developed a general solution in a different way.


I have this: Arthur Brown - The Crazy World Of Arthur Brown - 08 - Fire.mp3

I want this: Brown, Arthur - The Crazy World Of Arthur Brown - 08 - Fire.mp3

I did this to get it (and it works like a champ):

Match: ^([A-Z][a-z]*) ([A-Z][a-z]*)(.*)
Replace: \2, \1\3
BRUlvr100
 
Posts: 1
Joined: Sun Oct 16, 2011 4:44 am

Re: flipping names exchange swap move first last name, firstname

Postby rasmus » Sun Dec 11, 2011 3:27 am

Hi,

I'm really new to regex too..
I buy music on 2 different sites and they name the files differently, so basicly what I want to do is make them the same.

So I have a file like this

Artist Name - Label Name - Track Name (Remix name)

I wanna make look like this

Artist Name - Track Name - Remix Name - Label Name

How do I do this?
rasmus
 
Posts: 3
Joined: Sun Dec 11, 2011 3:22 am

Re: flipping names exchange swap move first last name, firstname

Postby Jane » Sun Dec 11, 2011 7:57 pm

This is a variation of
http://www.bulkrenameutility.co.uk/forum/viewtopic.php?f=3&t=1515
and many other samples throughout the forum.
The answer can be simple to complex depending on how how flexible you want it to be and how accurately your example represents the range of file names you want to rename.
For example, the sample you gave
Artist Name - Label Name - Track Name (Remix name)

shows a single space on both sides of each dash and a space before the opening parenthesis.
If this is always the case you could match it with:
(.+) - (.+) - (.+) \((.+)\)
and replace with
\1 - \3 - \4 - \2

However, if even one space is missing it will not match.
If you weren't sure of the number of spaces, you could use match with:
(.+)-(.+)-(.+)\((.+)\)
and replace with
\1 - \3 - \4 - \2 or \1-\3-\4-\2 depending on whether you wanted at least one space on each side of the hyphen in the renamed file name.

This would be more flexible but you could end up with a variable number of spaces around the hyphens and before the parenthesis.
If that isn't a problem you could use that.

Another problem with this type of regex (using .+ to get a match) is that in this case there is a huge amount of backtracking to get a match of a single file name. The first one above takes about 340 steps, the second about 314 steps. This could be significant if you are naming thousands of files. A better regex would be:
([^-]+) - ([^-]+) - ([^(]+) \(([^)]+)\) or ([^-]+)-([^-]+)-([^(]+)\(([^)]+)\), again depending on whether you are sure of the spaces around the hyphens etc.
These do not backtrack and the first will match in 12 steps!.
Finally, if you wanted to be able to match variable spacing and were fussy that the replacement would have exactly the right number of spaces you could use:
([^-]+\w)\s*-\s*([^-]+\w)\s*-\s*([^(]+\w)\s*\(([^)]+)\)
and replace with:
\1 - \3 - \4 - \2
This captures no surrounding spaces and allows for a varying number of spaces, and does it in about 32 steps.

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

Re: flipping names exchange swap move first last name, firstname

Postby rasmus » Mon Dec 19, 2011 4:02 pm

Thanks alot Jane...

Well the files are accurately named already ass they are from a pay site.

But some of them doesnt have the mix name because it is the original.
On other sites they have written (original mix) on all of them. I would like this for the ones that are missing.

Is there a way in regex to find files that do not have an paranthese and add to the end (Original Mix)

Thinks it a 2 step thing isn't it? First this, then move label name to the end.

Example: I have a folder with different names

Artist Name 1 - Label Name 1 - Track Name 1 (Remix 1)
Artist Name 2 - Label Name 2 - Track Name 2

And want the ones with a parenthese already to stay unchanged and put Original Mix on the other, like this

Artist Name 1 - Label Name 1 - Track Name 1 (Remix 1)
Artist Name 2 - Label Name 2 - Track Name 2 (Original Mix)

Cheers,
Rasmus
rasmus
 
Posts: 3
Joined: Sun Dec 11, 2011 3:22 am

Re: flipping names exchange swap move first last name, firstname

Postby Jane » Mon Dec 19, 2011 8:38 pm

Hi Rasmus,
Actually, doing that is quite simple with a Regex

Using the Regex(1) field
Match ^([^(]+)$
Replace \1 (Original Mix)

Include Ext UNCHECKED

Here's what the Regex means, breaking it down:

^ match must begin at the start of the name
( start a capture group
[^(] match only any character that is NOT a (
+ one or more times
) end of captured group
$ until we hit the end of the line

This will therefore only match lines in which, from start to finish, there are no opening parentheses.
If it does match, the whole filename is captured and stored in \1.
We use \1 and append (Original Mix) for the replace.
If it doesn't match, it is ignored and left unchanged.


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

Re: flipping names exchange swap move first last name, firstname

Postby rasmus » Tue Dec 20, 2011 2:11 pm

Thanks..

This was exactly the thing I was looking for.. happy to have discovered Regex.

And thanks for the help :)

Cheers,
Rasmus
rasmus
 
Posts: 3
Joined: Sun Dec 11, 2011 3:22 am

Re: flipping names exchange swap move first last name, firstname

Postby oilburner » Sat Mar 17, 2012 6:00 pm

I think iam getting to old for this as nothing works for me. i would love some help as i havent got a clue.
I have thousends of file labled not to my likeing eg

AH2002-04 - Twain, Shania - Any Man Of Mine.zip
i would like it to read

AH2002-04 - Shania Twain - Any Man Of Mine

can any one help me please
ive gone through the faq and nothing works :cry:
oilburner
 
Posts: 5
Joined: Sat Mar 17, 2012 5:44 pm

Re: flipping names exchange swap move first last name, firstname

Postby Jane » Sun Mar 18, 2012 12:31 am

Try
Regex(1)
Match:
(^[^-]+-[^-]+-)([^,]+),([^-]+)(-.+)
It selects the stuff between the dashes by looking for non dashes [^-]

Replace:
\1\3\2 \4

Include Ext. Not checked!

Works for me,
Jane
Jane
 
Posts: 24
Joined: Sat Aug 05, 2006 1:20 am

Re: flipping names exchange swap move first last name, firstname

Postby oilburner » Sun Mar 18, 2012 1:00 am

thanks very much it works :D
oilburner
 
Posts: 5
Joined: Sat Mar 17, 2012 5:44 pm

Re: flipping names exchange swap move first last name, firstname

Postby oldschoola » Thu May 24, 2012 8:14 pm

can someone help me with my litlte dilema?
i have the folowing scenarios
lastname, firstname - id#.jpg
lastname,firstname - id#.jpg
lastname, firstname.jpg
lastname,firstname.jpg

lastname1 lastname2, firstname1 firstname2 - id#.jpg
lastname1 lastname2,firstname1 firstname2 - id#.jpg
lastname1, firstname1 firstname2 - id#.jpg
lastname1 lastname2, firstname1 - id#.jpg

^all of these also without the - id#.


i want to just change all of these to
****obviously depending on teh scenario the result would vary and it may take diff reg ex for each scenario above.
firstname lastname.jpg
firstname1 firstname2 lastname1 lastname2.jpg
firstname1 lastname1 lastname2.jpg
firstname1 firstname2 lastname1.jpg
oldschoola
 
Posts: 1
Joined: Thu May 24, 2012 8:09 pm

Re: flipping names exchange swap move first last name, firstname

Postby Stefan » Fri May 25, 2012 12:14 pm

oldschoola wrote:can someone help me with my litlte dilema?
i have the folowing scenarios
lastname, firstname - id#.jpg
lastname,firstname - id#.jpg
lastname, firstname.jpg
lastname,firstname.jpg

lastname1 lastname2, firstname1 firstname2 - id#.jpg
lastname1 lastname2,firstname1 firstname2 - id#.jpg
lastname1, firstname1 firstname2 - id#.jpg
lastname1 lastname2, firstname1 - id#.jpg

^all of these also without the - id#.


i want to just change all of these to
****obviously depending on teh scenario the result would vary and it may take diff reg ex for each scenario above.
firstname lastname.jpg
firstname1 firstname2 lastname1 lastname2.jpg
firstname1 lastname1 lastname2.jpg
firstname1 firstname2 lastname1.jpg


What would be the rule here?
Coma is the delimiter, followed by an space or not.
At the and there could be an sequence of space-dash-space-digits or not.
Swap around the coma, remove the coma itself and also possible space-dash-space-digits?

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

Re: flipping names exchange swap move first last name, firstname

Postby shchr2012 » Sat May 04, 2013 4:42 am

Hello,

Can someone help me out, I'm simply trying to rename some music files. I tried to figure it out but for the life of me can't figure how to swap based on the "-" hyphen separator.

Here is what I have now: Song Title - Artist.mp3
I am hoping to rename to: Artist - Song Title.mp3
NOTE: song title or the artist could have multiple words

This is what I tried but it doesn work. It looks like I am unable to define SongTitle and Artist as separate groups possibly because they have multiple words in each group??

RegEx (1)
Match String = (.+) ( - .+) (.+)
Replace String = \3 \2 \1

Any help is greatly appreciated.

Sincerely...Shad
shchr2012
 
Posts: 1
Joined: Sat May 04, 2013 4:11 am

Next

Return to Regular Expressions


cron