A Couple Of Simple Moves?

A swapping-ground for Regular Expression syntax

A Couple Of Simple Moves?

Postby titanjedi » Sun Aug 01, 2010 3:26 pm

need to rename:

Thorogood, George & The Destroyers - Who Do You Love

to

George Thorogood & The Destroyers - Who Do You Love

------------------------------------------------------------------------------------------

need to rename:

Buffett, Jimmy & Toby Keith - Piece Of Work

to

Jimmy Buffett & Toby Keith - Piece Of Work

------------------------------------------------------------------------------------------

need to rename:

Clay Walker - Few Questions, A

to

Clay Walker - A Few Questions

also

Metallica - Unforgiven, The

to

Metallica - The Unforgiven

------------------------------------------------------------------------------------------

Thanks a bunch
titanjedi
 
Posts: 2
Joined: Sun Aug 01, 2010 3:11 pm

Re: A Couple Of Simple Moves?

Postby Stefan » Sun Aug 01, 2010 9:27 pm

titanjedi wrote:need to rename:
Thanks a bunch


FROM:
Thorogood, George & The Destroyers - Who Do You Love
Buffett, Jimmy & Toby Keith - Piece Of Work
TO:
George Thorogood & The Destroyers - Who Do You Love
Jimmy Buffett & Toby Keith - Piece Of Work

Global rule:
1) match all signs till an coma and an space=======> "(.+), " ===> "Thorogood, "
2) match all signs till an ampersand and an space ==> "(.+) &" ===> George &
3) match all signs till the end ===================> "(.+)" ====> The Destroyers - Who Do You Love

Then replace with match 2, 1 and 3 ====> \2, \1 & \3

DO:
RegEx(1)
Match: (.+), (.+) & (.+)
Repla: \2, \1 & \3


---------------------

FROM:
Clay Walker - Few Questions, A
Metallica - Unforgiven, The
TO:
Clay Walker - A Few Questions
Metallica - The Unforgiven

1) match all till an dash and an space ===> "(.+) - " ===> "Clay Walker - "
2) match all till an coma and an space ==> "(.+), " ====> "Few Questions, "
3) match all till the end ==============> "(.+)" ======> "A"

DO:
RegEx(1)
Match: (.+) - (.+), (.+)
Repla: \1 - \3 \2


Untested, but should work. Maybe you have to adjust something at the regex.



General notes/ Disclaimer

Hope this helps ? :D
If yes, please help two others too. And consider an donation to the tools autor.


Please note:

Always don't trust me! Test with test files first!
* Usually i do a few tests on this issue only!
* So please test my solution with some test files first before you destroy your data.
* Select one or more files in the Name column to watch how the New Name will be.

RegEx is an pattern matching solution, so all your files have to fit into the same pattern.
If they not, you have to separate them and run some more actions against them.

To find your own solution you have to virtual (in mind) split your file names/strings into parts
following the rules of the regular expression syntax, see the help file coming with your application.
(Please note that there are several flavors of RE engines and also different implementations into apps
and even different ways of doing or thinking, so your expiriences may differ from my explanation)
Once you have split your string into parts you can decide which to use into replacement by grouping the pattern
into (...) parenthesis to which you can refer by using "\1" or "$1" signs later, or which to drop and which to modify.

My solution depends on the quality of your examples.
* It's always an good idea to provide all possibilities of file name pattern in question.
* That would give the supporter an change to do it right ;)
* If your real file names doesn't fit into your example pattern my solution may fail.
So provide us always real live examples of your file names. Or we have to extend the talk over several days.
(Of course you can sophisticate your secrets)

* Don't use this ' ' or " " -quotes from my explanation. They are only for clarification.
* '?' means non-greedy: stop at first match, instead of last possible.
* This (...) parenthesis are used to "group" what is found by this RegEx inside the ( )'s
to reuse this capture later as replacement by using \1 .
* Instead of ~ -signs, if used in my explanations, type an space/blank.


More Help
* online tester:
- http://rereplace.com/
- http://www.regextester.com/
- http://www.regexlib.com/RETester.aspx

* online help:
- www.regular-expressions.info
- www.regexlib.com/
- www.regexlib.com/CheatSheet.aspx

See this both oldest threads in the "Regular Expressions" forum 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
There you will find more examples and tips as you may find in other threads in the "Regular Expressions" sub-forum.
Stefan
 
Posts: 736
Joined: Fri Mar 11, 2005 7:46 pm
Location: Germany, EU

Re: A Couple Of Simple Moves?

Postby titanjedi » Sun Aug 01, 2010 11:27 pm

thanks a million. i really appreciate your time and know-how.
titanjedi
 
Posts: 2
Joined: Sun Aug 01, 2010 3:11 pm


Return to Regular Expressions