Trying to swap date format

A swapping-ground for Regular Expression syntax

Trying to swap date format

Postby francis488 » Fri May 03, 2013 2:16 am

I am trying to swap the dates around in a filename to get YYYY-MM-DD instead of DD-MM-YYYY. As it is now my files look like (example):

06-08-2011 - author - title

for some reason (\d\d)-(\d\d)-(\d\d\d\d) - (.*) with \3-\2-\1 - \4 doesnt work, it doesnt seem to read the initial zero at the front of the date. Any help would be appreciated.
francis488
 
Posts: 6
Joined: Fri May 03, 2013 2:12 am

Re: Trying to swap date format

Postby Admin » Fri May 03, 2013 2:28 am

Hi, I tried and your RegEx works fine. Which 0 is missing in your testing?
Admin
Site Admin
 
Posts: 2351
Joined: Tue Mar 08, 2005 8:39 pm

Re: Trying to swap date format

Postby francis488 » Sat May 04, 2013 1:34 am

For example in this one:

06-08-2011 - author - title


I can't group the 06 at the front, only the 08 and the 2011. Another problem is that it only does this when I select some titles. For others, not even any "new name" shows up in green, even though i still have the same number format. Does the regex compiler read from start to end in every case?
francis488
 
Posts: 6
Joined: Fri May 03, 2013 2:12 am

Re: Trying to swap date format

Postby francis488 » Sat May 04, 2013 1:39 am

It may be some special characters (the cyrillic "be" character) in the filename are throwing it off, because I've used this regex on other files and it worked fine.
francis488
 
Posts: 6
Joined: Fri May 03, 2013 2:12 am

Re: Trying to swap date format

Postby francis488 » Sat May 04, 2013 1:45 am

Okay yep, that was it. I manually removed the charater and did the regex and it worked. Is there any way to remove this character, or ideally, remove where it appears in the filename entirely? The filename looks like:

06-08-2011 - author {<some text and numbers along with cyrillic character, to be removed>) (title).mp4

yes that's a brace, then a parenthasi.
francis488
 
Posts: 6
Joined: Fri May 03, 2013 2:12 am

Re: Trying to swap date format

Postby Stefan » Sat May 04, 2013 9:26 am

francis488 wrote: Is there any way to remove this character, or ideally, remove where it appears in the filename entirely?


You may want to check out the 'Remove(5)' section.



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

Re: Trying to swap date format

Postby francis488 » Sat May 04, 2013 4:57 pm

Stefan wrote:
francis488 wrote: Is there any way to remove this character, or ideally, remove where it appears in the filename entirely?


You may want to check out the 'Remove(5)' section.



.



I got it to remove that character, but now I need it to remove everything bounded by the first brace then a parenthais in the filename. For example I have 2011-06-08 - author {numbers and letters in here, delete this) (title.ext
francis488
 
Posts: 6
Joined: Fri May 03, 2013 2:12 am

Remove curly brackets brace parenthesis and in between

Postby Stefan » Sat May 04, 2013 8:31 pm

BEFORE:
06-08-2011 - author {some text and numbers to be removed) (title).mp4

AFTER:
06-08-2011 - author (title).mp4

RULE:
Remove all between the curly bracket and the first closing parenthesis.

We use an regex to match everything before the curly bracket and store that in backreference group () 1. >>> "(.+)"
Then we match everything non-greedy till first closing parenthesis, which we have to escape by an backslash because it is a regex meta sign, followed by one space. >>> "{.+?\) "
(Note: non-greedy is not really needed here because we order in our regex that there has to be something after the closing parenthesis, so it can be only the first one in this example we mean)
Last we match everything till before the extension and store that in group 2. >>> "(.+)"
In the replacement we only have what we had matches in first and second backreferencing parenthesis groups (...).

USE:
RegEx(1)
Search: "(.+){.+?\) (.+)"
Replace: "\1\2"


Don't use the quotes "", they are only for clarifying.
"[ ] Include Ext." is unchecked.
"Options > Ignore... > File Extensions" is unchecked.
Select a few files in the Name column to see what happens in the NewName column.
More about RegEx there >>> http://www.bulkrenameutility.co.uk/forum/viewtopic.php?f=3&t=96
Remember to test this with test files first. And always do backups before you manipulate your important real files!


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

Re: Trying to swap date format

Postby francis488 » Sun May 05, 2013 5:09 pm

Thanks, that worked perfectly! Only one question, I still don't understand, after reading your link, what is meant by a "non greedy" character and why you need to use the ? mark. Thanks
francis488
 
Posts: 6
Joined: Fri May 03, 2013 2:12 am


Return to Regular Expressions