Re: flip lastname firstname - title .....

A swapping-ground for Regular Expression syntax

Re: flip lastname firstname - title .....

Postby lorenzo » Tue Jul 10, 2007 1:45 am

The answers provided in the topic mentioned in the title almost satisfy this problem, but isn't as general as it could be (I think).

I have authors names (firstname(s) middle(s) lastname) appearing before titles with one hyphen as a separator. The lastname is always the last word before the first hyphen.

A. Bertram Chandler - Big Black Mark.pdf
Alan Dean Foster - Cyber way.pdf
Alastair Reynolds - Diamond Dogs.pdf
Alan F. Troop - Dragon DelaSangre.pdf
J. R. R. Tolkien - THe Fellowship of the Ring
Barb & J. C. Hendee - Noble Dead 01 - Dhampir.pdf

I'd like to be able to reorder the names and place them at the back of the line with a '$' separating the title from the author. Like this....

Big Black Mark.pdf $ Chandler, A. Bertram
Cyber way.pdf $ Foster, Alan Dean
Diamond Dogs.pdf $ Reynolds, Alastair
Dragon DelaSangre.pdf $ Troop, Alan F.
THe Fellowship of the Ring $ Tolkien, J. R. R.
Noble Dead 01 - Dhampir.pdf $ Hendee, Barb & J. C.

I've played around with identifying the name parts as \1, \2 etc. but I haven't found out how to allow for the variability in the number of name parts.

Thanks in advance.
lorenzo
 
Posts: 2
Joined: Sun Dec 11, 2005 11:36 pm
Location: Berkeley, CA

Postby nevernat » Fri Jul 13, 2007 8:57 am

hi, lorenzo!

WOW!!! SOLVED!!!

Code: Select all
Match=^([\w.& ]*) ([\w. ]*)( - )(.*)
Replace=\4 $ \2, \1


remember that you have to toggle the 'Include Extension' option and set on 'remove' the "Extension" box (down to right in the main window)

IT WORKS VERY WELL!! :wink:
nevernat
 
Posts: 2
Joined: Sat Jul 16, 2005 5:09 pm

Postby lorenzo » Mon Jul 16, 2007 9:16 pm

I've been away this weekend for a family celebration and didn't access my computer until just now. I also never expected a reply so quickly.

Yes, this worked as I had hoped. Now I have to study what it is you did !
Thank you very much :)
lorenzo
 
Posts: 2
Joined: Sun Dec 11, 2005 11:36 pm
Location: Berkeley, CA

Postby Admin » Mon Jul 16, 2007 10:24 pm

Most regexp stuff is beyond me...this definitely is :-)

Thanks nevernat !!


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

Postby bobkoure » Fri Jul 27, 2007 5:13 pm

Or even

^([\w.& ]+?)[ ]*(\w+)[ ]*-[ ]*(.+)
to
\3 $ \2, \1

... which deals with some possible additional spaces...

Note that
* is zero or more matches
+ is one or more matches
If you're going to use a backreference for renaming (something in parentheses that gets used as \1, \2, etc in the "to" line) I'd suggest using the '+' as then, if there are zero matches, BRU won't try to rename that file.
Did that make sense?
bobkoure
 
Posts: 16
Joined: Mon Jul 10, 2006 5:38 pm


Return to Regular Expressions