View previous topic :: View next topic |
Author |
Message |
mnemon
Joined: 04 Oct 2011 Posts: 3
|
Posted: Tue Oct 04, 2011 8:10 pm Post subject: Moving a String within a file plus replacing underscores |
|
|
Hi,
appologies in advance, I am not good enough in regex to cobble together the expression I am looking for from the examples already posted in this forum.
I am trying to rename a couple of files:
053191516x_soandso_press_analysis_of_criminal_evidence_jul_2005.pdf to
analysis_of_criminal_evidence-soandso_press-053191516-jul_2005.pdf
so the logic of the result is <title>-<publisher>-<isbn>-<date>.pdf
With '(^\d{6})(.*)-(.*)' i can grab the numbers, but I dont know how to identify the `_` to replace by `-`.
Any help gratefully accepted. |
|
Back to top |
|
|
admin Site Admin
Joined: 09 Mar 2007 Posts: 448 Location: Canada
|
Posted: Wed Oct 05, 2011 6:36 pm Post subject: |
|
|
Try putting this in the renaming creator (do not include the single quotes):
Row: 1
Search: '(?E)^(\d*)(.*?)(.{3,3}_\d{4,4})'
Replace: '\2-\1-\3'
Row: 2
Search: '_'
Replace: '-'
This will take care of the isbn and the date.
But you need to find some way to spepcify how the title and publisher are separated and use the information to split the title/publisherinto 2 groups which can then be swapped.
Hope that helps.
Peter. |
|
Back to top |
|
|
mnemon
Joined: 04 Oct 2011 Posts: 3
|
Posted: Wed Oct 05, 2011 10:11 pm Post subject: Thanks! |
|
|
Thank you so much for the quick reply. The preview already looks awesome, but you are right, I need to identify the publisher, otherwise ALL "-"s will be replaces, wich looks weird.
The easiest way of identifying the publisher is probably by name, since most of the files have the same publisher.
The second possiblity would be "from the first underscore" to the string "press".
Any ideas how that might look like? |
|
Back to top |
|
|
admin Site Admin
Joined: 09 Mar 2007 Posts: 448 Location: Canada
|
Posted: Thu Oct 06, 2011 6:58 am Post subject: |
|
|
You could add another group into row 1:
Row: 1
Search: '(?E)^(\d*)(.*?press)(.*?)(.{3,3}_\d{4,4})'
Replace: '\3-\2-\1-\4'
Row: 2
Search: '_'
Replace: '-'
Row: 3
Search: '^\-'
Peter. |
|
Back to top |
|
|
mnemon
Joined: 04 Oct 2011 Posts: 3
|
Posted: Sat Oct 08, 2011 9:58 pm Post subject: Thanks! |
|
|
Worked like a charm, the understores at the files beginning where easy to remove.
Thank you again for your help and the great work you did with that tool! You should have gotten mail |
|
Back to top |
|
|
|