Move "The" to end of title but before release date (XXXX)

A swapping-ground for Regular Expression syntax

Move "The" to end of title but before release date (XXXX)

Postby esumsea » Wed Apr 03, 2019 9:15 pm

Hello! I have tried to work this out myself and search this forum but have not come up with a solution so I thought I would ask. I have a bunch of files in this format:
The Straight Story (1999) (Disney)

I would like to change them to this format:
Straight Story, The (1999) (Disney)

Please let me know how to do this and if you be so kind why it works. I have an expression for moving "The" in album titles but I cannot modify it to work with movie titles. If only I could wrap m head around regular expressions! :oops:
Thanks in advance!!! :D
esumsea
 
Posts: 4
Joined: Mon Jun 18, 2018 5:09 pm

Re: Move "The" to end of title but before release date (XXXX)

Postby therube » Thu Apr 04, 2019 4:15 am

I think this will get it.


> The Straight Story (1999) (Disney)

1:RegEx
Code: Select all
Match:  ^([Tt]he)\s(.*?)(\s\(.*)
Replace:  \2, \1\3


1) ^([Tt]he) | the, names that start with the | "The"
x) <sp>, eat the space following the word the
2) (.*?) | everything else, non-greedy, stopping at the first <sp><left paren> combination | "Straight Story"
3) (\s\(.*) | everything from the first <sp><left paren> combination | " (1999) (Disney)

Then rearrange, adding a comma into the mix.

> "Straight Story", "The" " (1999) (Disney)


Depending on your file names, this might be a bit more succinct:
Code: Select all
Match:  ^([Tt]he)\s(.*?)(\s\(\d\d\d\d\).*)

(I should have tested before closing... ;-).)
therube
 
Posts: 1314
Joined: Mon Jan 18, 2016 6:23 pm

Re: Move "The" to end of title but before release date (XXXX)

Postby esumsea » Thu Apr 04, 2019 4:11 pm

Thanks so much for this! It's been driving me crazy. I will try to digest your explanation and ask a few questions as I am not sure I fully understand your explanation.

For example,how does (.*?) eat everything else, non-greedy, stopping at the first <sp><left paren> combination? I believe (.*) means eat everything. How does the ? cause the function to stop at the "("?
I would think that the (\s\(.*) would have to be included within the parenthesis of (.*?) e.g. (.?(\s\(.*)), but obviously not. I guess the ? in (.*?) tells the function to eat everything until the next described condition, which in this case is (\s\(.*) or space followed by a "(" followed by anything else (.*). Is that so? Maybe you put the (\s\(.*) outside the (.*?) to delimit a 3rd group, to the sort it with the /3?

As such, using the expression (.*?) should always be followed by another condition. Correct?

Also, why do you find (\s\(\d\d\d\d\).*) to be more succinct? Since I know that the date always comes after the title, and that always starts with a "(" why bother putting in the "(\d\d\d\d\)"?
esumsea
 
Posts: 4
Joined: Mon Jun 18, 2018 5:09 pm

Re: Move "The" to end of title but before release date (XXXX)

Postby therube » Sun Apr 07, 2019 2:30 pm

(I'm not particularly good or knowledgeable at this stuff...)


? is the non-greedy part.

greedy:
(.*)(\()
Matches: The Straight Story (1999) (

non-greedy:
(.*?)(\()
Matches: The Straight Story (


I guess the ? in (.*?) tells the function to eat everything until the next described condition, which in this case is (\s\(.*) or space followed by a "(" followed by anything else (.*). Is that so?

That sound right to me.

Maybe you put the (\s\(.*) outside the (.*?) to delimit a 3rd group, to the sort it with the /3?

Well the \s is outside if everything, IOW it gets "eaten".
If it weren't eaten, you'd have an extra <sp> that you'd have to deal with.
When you set up your Replace: part, you can always add a <sp> (or whatever) in there as needed.

And as always, there is likely to be multiple way to accomplish the same goal.

As such, using the expression (.*?) should always be followed by another condition. Correct?

Not sure particularly, but I'd think it will just depend on the entire context?

why do you find (\s\(\d\d\d\d\).*) to be more succinct? Since I know that the date always comes after the title

"Since I know", so in your case, you may not need it.
As it is, I searched for a <sp>(, which is rather generalized.
Finds:
The Straight Story (1999)
and also:
The Straight Story (did you really intend on finding me?)

By adding the \d\d\d\d\, it will match the first but not the second.

Likewise it would also find:
The Straight Story (1999) (Happens to be the song playing at the moment.)
therube
 
Posts: 1314
Joined: Mon Jan 18, 2016 6:23 pm

Re: Move "The" to end of title but before release date (XXXX)

Postby esumsea » Sun Apr 07, 2019 11:07 pm

Thanks for the detailed response! I appreciate it greatly! :D It really clears things up.
esumsea
 
Posts: 4
Joined: Mon Jun 18, 2018 5:09 pm

Re: Move "The" to end of title but before release date (XXXX)

Postby gee-wiz » Sun Jun 14, 2020 7:23 pm

Hi I'am to looking for something very similar. I used the above for titles that have the year in brackets such as (1999) and tried to use the above to match years without brackets but with the following ^([Tt]he)\s(.*?)(\s\\d\d\d\d\.*) but it did not work. Could you please give guidance to the noted problem. Thx
gee-wiz
 
Posts: 4
Joined: Sun Jun 14, 2020 7:13 pm

Re: Move "The" to end of title but before release date (XXXX)

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

Examples of your file names?
therube
 
Posts: 1314
Joined: Mon Jan 18, 2016 6:23 pm

Re: Move "The" to end of title but before release date (XXXX)

Postby gee-wiz » Mon Jun 15, 2020 7:00 pm

Some may look like the given example which your reg works great. But the greater portion of my folders/files have no brackets for the given release date such as (using the given example above) The Straight Story 1999. Though the actual maybe:

The Straight Story (1999) [x264]
The Straight Story (1999) [x265]
The Straight Story 1999 [x264]
The Straight Story 1999 [x265]
The Straight Story (1999) [x264][T]
The Straight Story (1999) [x265][T]
The Straight Story 1999 [x264][T]
The Straight Story 1999 [x265][T]
The Straight Story (1999) [x264][4k]
The Straight Story (1999) [x265][4k]
The Straight Story 1999 [x264][4k]
The Straight Story 1999 [x265][4k]...

The title given "The Straight Story (1999)" is an example of many possible different title names in the library and/or release dates.
gee-wiz
 
Posts: 4
Joined: Sun Jun 14, 2020 7:13 pm

Re: Move "The" to end of title but before release date (XXXX)

Postby therube » Tue Jun 16, 2020 2:36 pm

See if this gets it?
Code: Select all
Match:  ^([Tt]he)\s(.*?)\s([(]?\d\d\d\d[)]?)\s(.*)
Replace:  \2, The \3 \4

Code: Select all
The Straight Story (1999) [x264][4k] ->
   Straight Story, The (1999) [x264][4k]
The Straight Story 1999 [x264][T] ->
   Straight Story, The 1999 [x264][T]


Pretty much the only change is to check for 0 or 1 opening (& or closing) parens - [(]?
therube
 
Posts: 1314
Joined: Mon Jan 18, 2016 6:23 pm

Re: Move "The" to end of title but before release date (XXXX)

Postby gee-wiz » Wed Jun 17, 2020 3:55 am

Thanks works great.
gee-wiz
 
Posts: 4
Joined: Sun Jun 14, 2020 7:13 pm

Re: Move "The" to end of title but before release date (XXXX)

Postby gee-wiz » Wed Jun 17, 2020 3:59 am

If I wanted to place brackets around the release dates could the reg. be adjusted or would that be a separate reg.?
THX
gee-wiz
 
Posts: 4
Joined: Sun Jun 14, 2020 7:13 pm


Return to Regular Expressions