Re-arranging year placement w variable lengths

A swapping-ground for Regular Expression syntax

Re-arranging year placement w variable lengths

Postby sixtee5cuda » Sun Jan 04, 2015 10:19 pm

I want this example list:

ford focus (107) '2010.jpg
mazda 626 (101) '1978-82.jpg
studebaker president (130) '1934-35 independent.jpg
alfa romeo giulia 1600 (101) '1962-65 by bertone.jpg

to become:

2010 ford focus (107).jpg
1978 mazda 626 (101).jpg
1934 studebaker president (130) independent.jpg
1962 alfa romeo giulia 1600 (101) by bertone.jpg

So, the 4 digits after ' need to move to the beginning of the file name. "-dd" needs to be dropped from some file names. Words after 'dddd or 'dddd-dd need to be retained.

I discovered one way of doing this, would be to start by replacing the ' with "- ", then using some example RegEx's from here. I would prefer a single-step process.

Thank you for your help.
sixtee5cuda
 
Posts: 6
Joined: Sun Jan 04, 2015 10:02 pm

Re: Re-arranging year placement w variable lengths

Postby TheRegExpMaster » Sun Jan 04, 2015 10:47 pm

Hi, can you try this ?

RegEx(1)

MATCH :
Code: Select all
(.+) '(\d{4})(-\d{2})?(.*?)$

REPLACE :
Code: Select all
\2 \1\4
TheRegExpMaster
 
Posts: 25
Joined: Wed Nov 05, 2014 8:45 pm

Re: Re-arranging year placement w variable lengths

Postby sixtee5cuda » Mon Jan 05, 2015 1:49 pm

The RegEx provided works correctly, only for names ending in a 4-digit year ( '1964 ). For names with ( '1964-1966 ) or ( '1964 by Bertone ), it wants to rename the file to just the year.
sixtee5cuda
 
Posts: 6
Joined: Sun Jan 04, 2015 10:02 pm

Re: Re-arranging year placement w variable lengths

Postby TheRegExpMaster » Mon Jan 05, 2015 2:55 pm

sixtee5cuda wrote:So, the 4 digits after ' need to move to the beginning of the file name. "-dd" needs to be dropped from some file names. Words after 'dddd or 'dddd-dd need to be retained.
(...)
The RegEx provided works correctly, only for names ending in a 4-digit year ( '1964 ). For names with ( '1964-1966 ) or ( '1964 by Bertone ), it wants to rename the file to just the year.

Sorry, I didn't know that there could be more than 2 digits after the dash because you mentionned "dd" in your explanation (btw I didn't have problems for names ending with " '1964 by Bertone" :?).

Anyways, can you try this. It should solve your problem. If not, get back to me ;)
MATCH :
Code: Select all
(.+) '(\d{4})(-\d+)?(.*?)$
REPLACE :
Code: Select all
\2 \1\4

alfa romeo giulia 1600 (101) '1962 by bertone.jpg is renamed 1962 alfa romeo giulia 1600 (101) by bertone.jpg
alfa romeo giulia 1600 (101) '1962-1962 by bertone.jpg is renamed 1962 alfa romeo giulia 1600 (101) by bertone.jpg
alfa romeo giulia 1600 (101) '1962-65 by bertone.jpg is renamed 1962 alfa romeo giulia 1600 (101) by bertone.jpg
ford focus (107) '2010.jpg is renamed 2010 ford focus (107).jpg
mazda 626 (101) '1978-82.jpg is renamed 1978 mazda 626 (101).jpg
studebaker president (130) '1934-35 independent.jpg is renamed 1934 studebaker president (130) independent.jpg
TheRegExpMaster
 
Posts: 25
Joined: Wed Nov 05, 2014 8:45 pm

Re: Re-arranging year placement w variable lengths

Postby sixtee5cuda » Mon Jan 05, 2015 3:36 pm

Sorry, I was wrong to type ( '1964-1966 ), when I meant ( '1964-66 ).

I am testing using a subset of 82 files, compared to a full list around 1000. For the full list, your current RegEx seems to correctly fix over half of the entries. For the subset of 82, much fewer. Failure examples:

AC Aceca '1954-63.jpg
becomes
1954 467.jpg

Alfa Romeo 6C 1750 GS '1930–32 ?????? Zagato
becomes
1960 j.jpg (yes, many names have this cyrillic word)

I suspect the cyrillic characters, combined with many names not containing (), may be the root of the problem.

Names having ( 'dddd-dd ) without any ()'s, seem to be failing.

Thank you for working through this for me.
sixtee5cuda
 
Posts: 6
Joined: Sun Jan 04, 2015 10:02 pm

Re: Re-arranging year placement w variable lengths

Postby TheRegExpMaster » Mon Jan 05, 2015 3:55 pm

sixtee5cuda wrote:I suspect the cyrillic characters, combined with many names not containing (), may be the root of the problem.

Yes, unfortunately Bulk Rename Utility has a problem with special characters :(
BRU cannot match special characters from French, German, Cyrillic words, etc. And sometimes there are even special characters that are invisible to the human eye.

So you will have to rename manually all the files that contain special characters (I know your pain, I'm French and have to do this a lot).

This is a bug of BRU because the original Perl RegEx engine doesn't have this problem. ".+" is supposed to match everything, including the special characters.
TheRegExpMaster
 
Posts: 25
Joined: Wed Nov 05, 2014 8:45 pm

Re: Re-arranging year placement w variable lengths

Postby sixtee5cuda » Mon Jan 05, 2015 4:17 pm

I'll eliminate the cyrillic words, which leaves the problem with:

AC Aceca '1954-63.jpg

Sometimes, the () contain 3 digits, sometimes 4. Also, some names have words in ().

I eliminated the cyrillic word. File name which has "by" instead of the cyrillic word, would be change to:
1969 .jpg
sixtee5cuda
 
Posts: 6
Joined: Sun Jan 04, 2015 10:02 pm

Re: Re-arranging year placement w variable lengths

Postby TheRegExpMaster » Mon Jan 05, 2015 4:52 pm

I'm not sure I understand :oops: Can you give examples ?

For me, AC Aceca '1954-63.jpg is correctly renamed 1954 AC Aceca.jpg

The RegEx I gave you shouldn't have problem with parenthesis because it renames based on everything that follows the 4 year digit so it doesn't matter whether there are parenthesis or not in the filename.

When doing tests, please make sure that you rename the files manually by typing all the letters instead of doing copy/paste because it could copy special characters that are invisible to the eye.
TheRegExpMaster
 
Posts: 25
Joined: Wed Nov 05, 2014 8:45 pm

Re: Re-arranging year placement w variable lengths

Postby sixtee5cuda » Mon Jan 05, 2015 5:50 pm

I re-typed the file name for the example AC Aceca, and your RegEx performed properly.

There must be an illegal character in there, which is not visible.

I guess this one can be marked "solved".
sixtee5cuda
 
Posts: 6
Joined: Sun Jan 04, 2015 10:02 pm

Re: Re-arranging year placement w variable lengths

Postby TheRegExpMaster » Mon Jan 05, 2015 6:17 pm

sixtee5cuda wrote:I re-typed the file name for the example AC Aceca, and your RegEx performed properly.

Glad I could help ;) But the non-matching of special characters is a major annoyance that I hope will be solved in the next versions of BRU. Because of this bug, you will have to check every single file :x
TheRegExpMaster
 
Posts: 25
Joined: Wed Nov 05, 2014 8:45 pm

Re: Re-arranging year placement w variable lengths

Postby sixtee5cuda » Tue Jan 06, 2015 4:45 am

The Dash between the years was an illegal character, in every file name containing dddd-dd. Changing that, and removing the common cyrillic word, allowed your RegEx to correctly change over 2500 file names.

Thank you again for your assistance.
sixtee5cuda
 
Posts: 6
Joined: Sun Jan 04, 2015 10:02 pm


Return to Regular Expressions