flip lastname, firstname - title

A swapping-ground for Regular Expression syntax

Re: flip lastname, firstname - title

Postby bobkoure » Wed Dec 02, 2009 10:58 pm

1) lastname, firstname - title - idcode
2) idcode - lastname, firstname, title
3) idcode - title - lastname, firstname


OK - you've got 3 elements on each line, separated by ' - ' in 3 different patterns?
How do you tell which pattern you've got?
bobkoure
 
Posts: 16
Joined: Mon Jul 10, 2006 5:38 pm

Re: flip lastname, firstname - title

Postby ScorpiousDelectus » Thu Dec 03, 2009 2:39 am

Sorry Stefan, I had a bit of trouble following what you were saying...

I'm just looking to swap the lastname and firstname around.

Bobkoure: Each file format is in a different folder, so all the files that are formatted lastname, firstname - title - idcode are in one folder, idcode - lastname, firstname, title in another and idcode - title - lastname, firstname in another. I'm assuming therefore I just need a variation on the

^(\w+), *([\w \.]+)[ ]+-[ ]*(.*)
\2 \1 - \3

so that it applies to the second section and then the third.
ScorpiousDelectus
 
Posts: 7
Joined: Wed Dec 02, 2009 5:50 pm

Re: flip lastname, firstname - title

Postby bobkoure » Thu Dec 03, 2009 3:23 am

Hmmm... pattern 3 really has a comma between firstname and title?
Are there embedded spaces in any of your fields (got a firstname of "billie jo", for instance)?

Regex is loads easier to write than write about once you're past the learning curve...
bobkoure
 
Posts: 16
Joined: Mon Jul 10, 2006 5:38 pm

Re: flip lastname, firstname - title

Postby ScorpiousDelectus » Thu Dec 03, 2009 3:36 am

Oh crap, good pick-up, no 2) should be idcode - lastname, firstname - title.

Some have double barrel names "john, olivia newton" while some have two names separated by an ampersand "Diamond, Neil & Barbra Streisand"
ScorpiousDelectus
 
Posts: 7
Joined: Wed Dec 02, 2009 5:50 pm

Re: flip lastname, firstname - title

Postby bobkoure » Thu Dec 03, 2009 4:38 am

So they're all something - something - something (i.e. 3 parts always separated by ' - ')?
First step, shuffle parts into the order you want.
^([^-]+)[ ]-[ ]([^-]+)[ ]-[ ]([^-]+)$
will grab all 3 "somethings" - and you can refer to them as \1, \2 and \3
So to change nothing, your output would be \1 - \2 - 3 (not that you would actually bother to do that - just trying to be clear here).
To convert pattern 2 to pattern 1, use the above regex with the output
\2 - \3 - \1
see how that works?
To convert pattern 3 to pattern 1, use the above regex with the output
\3 - \2 - \1

Of course, use BRU's very nice change-preview feature to see what you're going to get, make sure I haven't gotten the order wrong...
bobkoure
 
Posts: 16
Joined: Mon Jul 10, 2006 5:38 pm

Re: flip lastname, firstname - title

Postby ScorpiousDelectus » Wed Dec 09, 2009 4:06 am

bobkoure wrote:So they're all something - something - something (i.e. 3 parts always separated by ' - ')?
First step, shuffle parts into the order you want.
^([^-]+)[ ]-[ ]([^-]+)[ ]-[ ]([^-]+)$
will grab all 3 "somethings" - and you can refer to them as \1, \2 and \3
So to change nothing, your output would be \1 - \2 - 3 (not that you would actually bother to do that - just trying to be clear here).
To convert pattern 2 to pattern 1, use the above regex with the output
\2 - \3 - \1
see how that works?
To convert pattern 3 to pattern 1, use the above regex with the output
\3 - \2 - \1

Of course, use BRU's very nice change-preview feature to see what you're going to get, make sure I haven't gotten the order wrong...


Yes, they're all something - something - something.*

I've spent the last week or so fixing the 23,600 files that were formatted in the original way with the name in the first bracket. I've spent a bit of time today poring over the manual and experimenting with suggestions made here and I simply can't get my head around it. I think perhaps what is confusing me is the original formula listed at the beginning of this thread uses commands not listed in the manual (/w for instance) and your formula doesn't list and alphanumeric characters at all so I don't understand what the formulas are actually achieving.

The test files are:

Thomson, Cyndi - What I really Meant To Say - Sc1009-04.zip (to test name in first section)
Johnson, Carolyn Dawn - Complicated - Sc1009-05.zip (to test name in first section where the name has two names before the surname)
Sc7224-18 - Glitter, Gary - Rock And Roll (Part2).zip (to test name in second section)
Scl1512-07 - Santa Rosa, Gilberto - Que Alguien Me Diga.zip (to test name in second section where the name has two names before the surname)
Sc8933-03 - Be As You Are - Chesney, Kenny.zip (to test name in third section)

Sorry for being a pain :/
ScorpiousDelectus
 
Posts: 7
Joined: Wed Dec 02, 2009 5:50 pm

Re: flip lastname, firstname - title

Postby ScorpiousDelectus » Sun Dec 13, 2009 2:54 am

Ok, hopefully the last post on this...

I've been able to get around the files formatted idcode - name - title by moving the "idcode" to the end and then applying the original formula but now I have the idcode - title - name files. Is there maybe a way I can swap the "idcode" and "name" sections? That might make things easier. Each section is separated by the " - " deliminator.
ScorpiousDelectus
 
Posts: 7
Joined: Wed Dec 02, 2009 5:50 pm

Re: flip lastname, firstname - title

Postby Stefan » Sun Dec 13, 2009 11:30 am

ScorpiousDelectus wrote: a way I can swap the "idcode" and "name" sections?
Each section is separated by the " - " deliminator.


If you have an question you should provide real example file names incl. wanted example results
so one can give you an valid RegEx and not have to do the work twice.

Given on your last post i just guess:
Search for ALL till SpaceDashSpace
then for the next ALL till SPACE-SPACE
then for the next ALL till SPACE-SPACE
then... and so on, as often as you have parts divided by " - ".

The RegEx for to search for ALL is .+
But group this by () for an back-reference: (.+)

So use
RegEx(1)
Match: (.+) - (.+) - (.+) - (.+)
Replace: \1 - \3 - \4 - \2 or any order you like.


See this older threads for an RegEx syntax overview:
=> Getting Started: http://www.bulkrenameutility.co.uk/forum/viewtopic.php?f=3&t=5
=> Go ahead: http://www.bulkrenameutility.co.uk/forum/viewtopic.php?f=3&t=27
Stefan
 
Posts: 736
Joined: Fri Mar 11, 2005 7:46 pm
Location: Germany, EU

Re: flip lastname, firstname - title

Postby ScorpiousDelectus » Sun Dec 13, 2009 1:18 pm

Stefan wrote:
ScorpiousDelectus wrote: a way I can swap the "idcode" and "name" sections?
Each section is separated by the " - " deliminator.


If you have an question you should provide real example file names incl. wanted example results
so one can give you an valid RegEx and not have to do the work twice.

Given on your last post i just guess:
Search for ALL till SpaceDashSpace
then for the next ALL till SPACE-SPACE
then for the next ALL till SPACE-SPACE
then... and so on, as often as you have parts divided by " - ".

The RegEx for to search for ALL is .+
But group this by () for an back-reference: (.+)

So use
RegEx(1)
Match: (.+) - (.+) - (.+) - (.+)
Replace: \1 - \3 - \4 - \2 or any order you like.


See this older threads for an RegEx syntax overview:
=> Getting Started: http://www.bulkrenameutility.co.uk/forum/viewtopic.php?f=3&t=5
=> Go ahead: http://www.bulkrenameutility.co.uk/forum/viewtopic.php?f=3&t=27


Example would be:

Sc8933-03 - Be As You Are - Chesney, Kenny.zip

The characters and number of characters vary in each segment, but are always separated by a " - "
ScorpiousDelectus
 
Posts: 7
Joined: Wed Dec 02, 2009 5:50 pm

Re: flip lastname, firstname - title

Postby Stefan » Sun Dec 13, 2009 1:41 pm

ScorpiousDelectus wrote:
Stefan wrote:
ScorpiousDelectus wrote: a way I can swap the "idcode" and "name" sections?
Each section is separated by the " - " deliminator.


If you have an question you should provide real example file names incl. wanted example results
so one can give you an valid RegEx and not have to do the work twice.

Given on your last post i just guess:
Search for ALL till SpaceDashSpace
then for the next ALL till SPACE-SPACE
then for the next ALL till SPACE-SPACE
then... and so on, as often as you have parts divided by " - ".

The RegEx for to search for ALL is .+
But group this by () for an back-reference: (.+)

So use
RegEx(1)
Match: (.+) - (.+) - (.+) - (.+)
Replace: \1 - \3 - \4 - \2 or any order you like.


See this older threads for an RegEx syntax overview:
=> Getting Started: http://www.bulkrenameutility.co.uk/forum/viewtopic.php?f=3&t=5
=> Go ahead: http://www.bulkrenameutility.co.uk/forum/viewtopic.php?f=3&t=27


ScorpiousDelectus wrote:Example would be:

Sc8933-03 - Be As You Are - Chesney, Kenny.zip

The characters and number of characters vary in each segment, but are always separated by a " - "

OK.
And what means "swap the "idcode" and "name" sections" ?
I guess you want to get:
Chesney, Kenny - Be As You Are - Sc8933-03.zip

So use
RegEx(1)
Match: (.+) - (.+) - (.+)
Replace: \3 - \2 - \1

Explanation:
With RegEx (.+) - (.+) - (.+) you can access the content of the first group in replace field by \1, the second by \2, and so on.
\1 should hold> Sc8933-03
\2 should hold> Be As You Are
\3 should hold> Chesney, Kenny
Then just order the replacement as you want it, and add dashes in between on your own.
Stefan
 
Posts: 736
Joined: Fri Mar 11, 2005 7:46 pm
Location: Germany, EU

Re: flip lastname, firstname - title

Postby ScorpiousDelectus » Sun Dec 13, 2009 10:26 pm

That is absolutely brilliant! Thanks everyone for your help :)
ScorpiousDelectus
 
Posts: 7
Joined: Wed Dec 02, 2009 5:50 pm

Re: flip lastname, firstname - title

Postby Anspre » Fri Jul 09, 2021 11:17 am

Hi, I am new to this forum and tried this, but BRU does not give me the option to rename (it is greyed out)

My current folder names

surname, name (sometimes with another initial)
which I would like to change to
name initial (if any) surname

Please assist
Anspre
 
Posts: 3
Joined: Tue Jun 20, 2017 2:37 pm

Re: flip lastname, firstname - title

Postby Admin » Wed Jul 14, 2021 1:30 am

Hi, can you post a few examples of from -> to names required. thanks
Admin
Site Admin
 
Posts: 2343
Joined: Tue Mar 08, 2005 8:39 pm

Previous

Return to Regular Expressions