Swap first 2 words

Post any Bulk Rename Utility support requirements here. Open to all registered users.

Swap first 2 words

Postby gatlat » Mon Feb 22, 2010 4:22 am

I would like to swap the first 2 words of files and place a comma at the end of the first word. The files have more than 2 words in them. The constant between the first 2 words of the file is a space

eg: Angela Mitchell - 2010-02-22 - DSU9999.pdf becomes Mitchell, Angela - 2010-02-22 - DSU9999.pdf
gatlat
 
Posts: 2
Joined: Mon Feb 22, 2010 3:47 am

Re: Swap first 2 words

Postby Stefan » Mon Feb 22, 2010 2:11 pm

gatlat wrote:I would like to swap the first 2 words of files
and place a comma at the end of the first word.

The files have more than 2 words in them.
The constant between the first 2 words of the file is a space

eg:
Angela Mitchell - 2010-02-22 - DSU9999.pdf
becomes
Mitchell, Angela - 2010-02-22 - DSU9999.pdf

Hi gatlat, welcome.

FROM:
Angela Mitchell - 2010-02-22 - DSU9999.pdf
TO:
Mitchell, Angela - 2010-02-22 - DSU9999.pdf

Use RegEx to match parts of your file name:
1) match word one till an space ==> '(.+)~' ==> should get 'Angela'
Hint: This (...) are capture groups to hold what is found by the RegEx and use it to replace later.
2) match second word till an space ==> '(.+)~' ==> should get 'Mitchell'
3) match the rest of file name ==> '(.+)' ==> should get '- 2010-02-22 - DSU9999'

Use
RegEx(1)
Match: '(.*?)~(.*?)~(.*)'
Repla: \2,~\1\3


Don't use this ' -quotes. They are only for explanations.
'?' means non-greedy: stop at first blank, instead of last.
Instead of ~ -signs type an space/blank.
Match: (.*?) (.*?) (.*)
Repla: \2, \1\3





HTH? :D
If yes: please help two others too.
Tell us how it works.
Note: if your other file names has an other pattern then your example, then this solution may fail.



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.
Stefan
 
Posts: 736
Joined: Fri Mar 11, 2005 7:46 pm
Location: Germany, EU

Re: Swap first 2 words

Postby gatlat » Tue Feb 23, 2010 10:41 pm

Solution worked a treat. Thanks heaps.
gatlat
 
Posts: 2
Joined: Mon Feb 22, 2010 3:47 am


Return to BRU Support