Deleting all but Year between Parenthesis

A swapping-ground for Regular Expression syntax

Deleting all but Year between Parenthesis

Postby mwcook52 » Mon Nov 11, 2019 11:23 am

I've been struggling to modify the following sample of file names so that only the year remains within parenthesis:

2307.Winters.Dream.(43.2016.1080p).mkv
Captain Fantastic.(80.2017.x720p).mkv
tag.(67.1999.720i).mkv

desired results:

2207.Winters.Dream.(2016).mkv
Captain Fantastic.(2017).mkv
tag.(1999).mkv

One note that may be helpful is that there is always a two digit number with the period before the date.

My sense is that it is probably not that difficult but after a couple of hours trying to fully understand regular expressions, I have been unable to make any significant progress. Any help would sure be appreciated.
mwcook52
 
Posts: 4
Joined: Mon Nov 11, 2019 9:45 am

Re: Deleting all but Year between Parenthesis

Postby therube » Mon Nov 11, 2019 1:34 pm

1:RegEx
Code: Select all
Match:  (.*\()\d\d\.(\d\d\d\d)
Replace:  \1\2)

Match anything up to & including the opening paren, (
Skip two digits followed by a dot, .
Match the following four digits

Keep the 1st part, skip the two digits, keep the four digit year, & add the closing paren, ), nothing else


As written, it is greedy so:

tag.(67.1999.720i) - Copy - tag.(67.1999.720i).mkv
becomes
tag.(67.1999.720i) - Copy - tag.(1999).mkv
therube
 
Posts: 886
Joined: Mon Jan 18, 2016 6:23 pm

Re: Deleting all but Year between Parenthesis

Postby mwcook52 » Mon Nov 11, 2019 6:12 pm

Thanks so much! Without fully understanding what I did, here's what I ended up using:

Match: (.*)\((.*?)(\d\d\d\d)
Replace: \1(\3).mkv

It worked perfectly for a few hundred files but failed of course on a few .avi files. Your approach is better because it preserves the file extension.
mwcook52
 
Posts: 4
Joined: Mon Nov 11, 2019 9:45 am

Re: Deleting all but Year between Parenthesis

Postby mwcook52 » Mon Nov 11, 2019 9:46 pm

therube wrote:1:RegEx
Code: Select all
Match:  (.*\()\d\d\.(\d\d\d\d)
Replace:  \1\2)


I just tried the above in Bulk Rename and it did not retain the mkv file extension. Is there a way to do that instead of forcing it in the replace like I did?
mwcook52
 
Posts: 4
Joined: Mon Nov 11, 2019 9:45 am

Re: Deleting all but Year between Parenthesis

Postby therube » Tue Nov 12, 2019 6:37 pm

Extensions are handled based upon options set.

Renaming Options | File/Folder Extensions... -> Rename File [Folder] Extensions...

Enable/disable as needed.


(Separately, 1:RegEx has to checkbox to specifically include extensions.)
therube
 
Posts: 886
Joined: Mon Jan 18, 2016 6:23 pm

Re: Deleting all but Year between Parenthesis

Postby mwcook52 » Tue Nov 12, 2019 11:01 pm

therube wrote:Extensions are handled based upon options set.

Renaming Options | File/Folder Extensions... -> Rename File [Folder] Extensions...

Enable/disable as needed.


(Separately, 1:RegEx has to checkbox to specifically include extensions.)


Ah! I could not understand why checking the Include Ext. checkbox did not work. I did not realize that there was a second action under options required to allow the inclusion of extensions.

THANKS!
mwcook52
 
Posts: 4
Joined: Mon Nov 11, 2019 9:45 am


Return to Regular Expressions