Regex for movie titles, square brackets around year

A swapping-ground for Regular Expression syntax

Regex for movie titles, square brackets around year

Postby pierce345 » Wed Jun 10, 2020 1:06 pm

I have movie filenames which use the typical naming schema:

Last.Year.at.Marienbad.1961.REMASTERED.1080p.BluRay.x264-DEPTH[rarbg]

which I wish to store in the more readable:

Last Year at Marienbad [1961]

Is this possible in a single regex operation? Obviously in sequential operations, one can replaces the dots with spaces then place the square brackets then truncate after "]" etc. but a single call would be much more elegant and save a lot of time.

Many thanks for anyone's kind help!
pierce345
 
Posts: 1
Joined: Wed Jun 10, 2020 12:56 pm

Re: Regex for movie titles, square brackets around year

Postby David » Mon Jun 15, 2020 10:23 am

RegEx(1)
Match: (.*?)\S(\d\d\d\d)(.*)
Replace: \1 [\2]

Replace(3)
Replace: .
with: space
David
 
Posts: 6
Joined: Mon Jun 15, 2020 7:25 am

Re: Regex for movie titles, square brackets around year

Postby therube » Mon Jun 15, 2020 2:44 pm

Ah, so the \S simply eats the last character, which happens to be the (.) [dot] before the year - in this case.
Suppose a single (.) [any character] would have worked as well.
therube
 
Posts: 1314
Joined: Mon Jan 18, 2016 6:23 pm

Re: Regex for movie titles, square brackets around year

Postby David » Tue Jun 16, 2020 2:23 am

therube wrote:Ah, so the \S simply eats the last character, which happens to be the (.) [dot] before the year - in this case.
Suppose a single (.) [any character] would have worked as well.

oh,thank you therube.
David
 
Posts: 6
Joined: Mon Jun 15, 2020 7:25 am


Return to Regular Expressions