Putting whatever comes before hyphen to end of filename

A swapping-ground for Regular Expression syntax

Putting whatever comes before hyphen to end of filename

Postby kilimanjaro » Sun Aug 02, 2015 10:49 am

I have a filename

Yongxiang Lu -A History of Chinese Science and Technology v3-Springer 2015

I want it to become

A History of Chinese Science and Technology v3-Springer Yongxiang Lu

but this also applies to:-

Studies of the Weatherhead East Asian Institute, Columbia University Emily T. Yeh-Taming Tibet landscape transformation and the gift of Chinese development-Cornell UP 2013

which I want to become

Taming Tibet landscape transformation and the gift of Chinese development-Cornell UP 2013 Studies of the Weatherhead East Asian Institute, Columbia University Emily T. Yeh

So the groups of characters being moved can range from just 2 groups to e.g. 10 groups or more,

Is there any way of doing this?
[I could replace the hyphen to a different expression if this would help and replace it at the end]
kilimanjaro
 
Posts: 2
Joined: Sun Aug 02, 2015 10:37 am

Re: Putting whatever comes before hyphen to end of filename

Postby Admin » Mon Aug 03, 2015 2:08 am

Hi, do you want to rotate the file name around the first "-" char , e.g.
A - B becomes B - A
A - B - C becomes B - C - A

thanks
Admin
Site Admin
 
Posts: 2343
Joined: Tue Mar 08, 2005 8:39 pm

Re: Putting whatever comes before hyphen to end of filename

Postby kilimanjaro » Mon Aug 03, 2015 9:30 am

yes kind of rotating just moving to the end

eg

ABC DE FG -HJIK LM NO.pdf

to become HJIK LM NO;ABC DE FG.pdf

or A B C DE-FG H.pdf

to become FG H;A B C DE.pdf


basically

(stuff before) [first hyphen] (stuff after) ====> (stuff after first hyphen)(stuff before)

but the stuff all has different character length

Thank you.
kilimanjaro
 
Posts: 2
Joined: Sun Aug 02, 2015 10:37 am

Re: Putting whatever comes before hyphen to end of filename

Postby Admin » Tue Aug 04, 2015 3:05 am

Stefan, I think this is easy to do with a matching regex?
Admin
Site Admin
 
Posts: 2343
Joined: Tue Mar 08, 2005 8:39 pm

Swap rearrange reorder parts around dash hyphen minus

Postby Stefan » Tue Aug 04, 2015 7:18 pm

Since the given examples are so different (space, or no space. Add hyphen or semicolon)
I am not sure we can give a 100% working solution. But the basics are:


FROM:
AB C - D EF.ext

TO:
D EF - AB C.ext



USE:
RegEx(1)
Match: (.+) - (.+)
Replace: \2 - \1


- - -

FROM:
ABC DE FG -HJIK LM NO.pdf

TO:
HJIK LM NO;ABC DE FG.pdf

USE:
RegEx(1)
Match: (.+) - (.+)
Replace: \2;\1



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

Re: Putting whatever comes before hyphen to end of filename

Postby Admin » Wed Aug 05, 2015 12:58 am

Yes, that's it, thanks Stefan :)
Admin
Site Admin
 
Posts: 2343
Joined: Tue Mar 08, 2005 8:39 pm


Return to Regular Expressions