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: 508
Joined: Fri Mar 11, 2005 7:46 pm
Location: Germany, EU


Return to Regular Expressions