Replace year with (year)

A swapping-ground for Regular Expression syntax

Replace year with (year)

Postby Joebow2 » Tue Jan 28, 2020 2:27 am

I have a directory with a bunch of different years. 1940 1955 2008 2017 2002 etc.


Finding Nemo 2001

I want to replace 2001 with (2001)
Joebow2
 
Posts: 3
Joined: Tue Jan 28, 2020 2:24 am

Re: Replace year with (year)

Postby Joebow2 » Tue Jan 28, 2020 2:40 am

I don’t see a edit post button so I’m replying.

Princess Mononoke 2001

The borrower arrietty 2010

The kingdom of dreams and madness 2013

Tales from earthsea 2006
Joebow2
 
Posts: 3
Joined: Tue Jan 28, 2020 2:24 am

Re: Replace year with (year)

Postby therube » Tue Jan 28, 2020 2:13 pm

This is rather basic & will not handle all situations but will probably work OK.
Just review the changes it wants to make before submitting.

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

Find (the first set of) anything, followed by a space, followed by 4 digits, followed by anything else
& put those 4 digits within parenthesis.


Code: Select all
Finding Nemo 2001
-> Finding Nemo (2001)

Finding Nemo episode 0001, Jan 28, 2020
-> Finding Nemo episode (0001), Jan 28, 2020

(note the "failure" in the second example)
therube
 
Posts: 889
Joined: Mon Jan 18, 2016 6:23 pm

Re: Replace year with (year)

Postby Joebow2 » Tue Jan 28, 2020 10:46 pm

therube wrote:This is rather basic & will not handle all situations but will probably work OK.
Just review the changes it wants to make before submitting.

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

Find (the first set of) anything, followed by a space, followed by 4 digits, followed by anything else
& put those 4 digits within parenthesis.


Code: Select all
Finding Nemo 2001
-> Finding Nemo (2001)

Finding Nemo episode 0001, Jan 28, 2020
-> Finding Nemo episode (0001), Jan 28, 2020

(note the "failure" in the second example)



This worked. Tyvm
Joebow2
 
Posts: 3
Joined: Tue Jan 28, 2020 2:24 am


Return to Regular Expressions