Adding ( ) to year

A swapping-ground for Regular Expression syntax

Adding ( ) to year

Postby dalben » Thu Jan 26, 2012 8:42 am

Hi,

First of all, great app. Thanks.

Next, I searched but didn't find much. Tried the self-help and got lost in code. So I'm hoping this is just a quick answer for someone.

What regex can I use to add parenthesis ( ) around a year in a file name. i.e. Zoo Time 1998.avi to Zoo Time (1998).avi ?

The length of file name varies but the year always tends to be at the end before the extension.

TIA.
dalben
 
Posts: 5
Joined: Thu Jan 26, 2012 8:38 am

Re: Adding ( ) to year

Postby Stefan » Thu Jan 26, 2012 8:33 pm

dalben wrote:FROM:
Zoo Time 1998.avi
TO:
Zoo Time (1998).avi

The length of file name varies but the year always tends to be at the end before the extension.


TRY:

RegEx(1)
Match: "(.+ )(\d\d\d\d)"
Repla: "\1(\2)"

Without the quotes.
"[ ] Include Extension" disabled.


Explanation:
(.+ ) ======> match one-or-more of any sign, followed by an space. Store in backreference group No.1
(\d\d\d\d) ==> match four single digits. Store in backreference group No.2

\1(\2) =====> replace with what is matched by first regex and stored in group No.1 with "\1",
==========> add an literal "(" yourself,
==========> get back what is stored in group 2 by using "\2",
==========> add an closing ")"



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

Re: Adding ( ) to year

Postby dalben » Fri Jan 27, 2012 2:27 am

That worked perfectly ! Thanks.
dalben
 
Posts: 5
Joined: Thu Jan 26, 2012 8:38 am


Return to Regular Expressions