Need to insert Parentheses in file

A swapping-ground for Regular Expression syntax

Need to insert Parentheses in file

Postby dukestravels07 » Thu Apr 15, 2010 6:57 pm

I'm trying to enclose the year of a film from:

This: Alien Directors Cut 1979.mkv
To: Alien Directors Cut (1979).mkv

I've read up on the regular expression stuff, but can't get it to work. Seems like a simple one I know...
Any help appreciated. Thanks!
dukestravels07
 
Posts: 1
Joined: Thu Apr 15, 2010 6:49 pm

Re: Need to insert Parentheses in file

Postby Stefan » Thu Apr 15, 2010 8:58 pm

dukestravels07 wrote:I'm trying to enclose the year of a film from:

This: Alien Directors Cut 1979.mkv
To: Alien Directors Cut (1979).mkv

I've read up on the regular expression stuff, but can't get it to work. Seems like a simple one I know...
Any help appreciated. Thanks!

Is it always that? Only 4 digits like an year, or are there file names with other digits too?
FROM:
Alien Directors Cut 1979.mkv
TO:
Alien Directors Cut (1979).mkv
Do:
RegEx(1)
Match: (.+)(\d\d\d\d) ---or shorter: (.+)(\d{4})
Repla: \1(\2)

Explanation:
Match all signs, till 4 digits are found, store that "all" before the digits in an capture group and the 4 digits in an own group by using ( ) parentheses.
First ( )-group will match "Alien Directors Cut" and the second four digits: "1979"
To access the first capture in the Replacement use \1, and for the digits group use \2.
Now add what you want in the replacement, as you want ( ) around the year use: (\2)
Stefan
 
Posts: 736
Joined: Fri Mar 11, 2005 7:46 pm
Location: Germany, EU

Re: Need to insert Parentheses in file

Postby trekerie » Tue Oct 25, 2016 6:45 am

This has solved most of my issues, but I can't quite figure out how to retain the quality identifier on the end. Example of what I would like to achieve:

FROM:
Alien Directors Cut 1979 1080p.mkv
TO:
Alien Directors Cut (1979) 1080p.mkv
trekerie
 
Posts: 2
Joined: Tue Oct 25, 2016 6:11 am

Re: Need to insert Parentheses in file

Postby therube » Tue Oct 25, 2016 7:51 am

1:RegEx
Code: Select all
Match:  (.+)(\d\d\d\d)(.+)
Replace:  \1(\2)\3
therube
 
Posts: 317
Joined: Mon Jan 18, 2016 6:23 pm

Re: Need to insert Parentheses in file

Postby trekerie » Tue Oct 25, 2016 4:26 pm

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


This got me very close. The issue that I had using this is that it put the parenthesis around the 1080 in the 1080p, rather than the year. However, I was able to find a solution using what you posted as groundwork.

1080p Files
RegEx(1)
Match: (.+)(\d\d\d\d)(.+)(\d{4})
Replace: \1[\2]\3\4
Replace (3)
Replace: 1080
With 1080p

720p Files
RegEx(1)
Match:(.+)(\d\d\d\d)(.+)(\d{3})
Replace:\1[\2]\3\4
trekerie
 
Posts: 2
Joined: Tue Oct 25, 2016 6:11 am

Re: Need to insert Parentheses in file

Postby KenP » Tue Oct 25, 2016 5:54 pm

@ trekerie

If you haven't already changed the file names try this.

RegEx (1)
Match: (.*)(\b\d{4}\b)(.*)
Replace: \1(\2)\3
KenP
 
Posts: 193
Joined: Sat Jul 30, 2016 11:25 am


Return to Regular Expressions