Page 1 of 1

help with {n.replaceFirst(/^(?i)(The|A|An)\s(.+)/, /\$2, \$1/)}

Posted: 11 Jan 2020, 04:06
by nzdreamer55
Hello everyone,

I have cobbled together a naming scheme from other peoples suggestions. If I have the word The, A, or An in the beginning, I like to have it be at the end of the title after a coma (for example the big lebowski => big lebowski, the) I was using {n.replaceFirst(/^(?i)(The|A|An)\s(.+)/, /\$2, \$1/)} to do this, but sometimes filebot will put the files into a folder called $2, $1 and I am not sure why. Here is what I think is happening
n = name
replaceFirst is the command to replace the first word it finds
Not sure about the ^(?i)
(The|A|An) are the things it is looking for to replace
\s(.+) not sure
and don't know what the $2, $1 is for but I think it is the pattern that gets filled in from the first part of the command.

I only get a little of the regex so any help would be appreciated.

Thanks

Re: help with {n.replaceFirst(/^(?i)(The|A|An)\s(.+)/, /\$2, \$1/)}

Posted: 11 Jan 2020, 04:15
by nzdreamer55
Should it maybe

{n.replaceFirst(/^(?i)(The|A|An)\s(.+)/, /$2, $1/)}

Re: help with {n.replaceFirst(/^(?i)(The|A|An)\s(.+)/, /\$2, \$1/)}

Posted: 11 Jan 2020, 06:39
by kim
tip #1 Read up on Regular expression
test out here: https://regexr.com/

btw: I think this is better:

Code: Select all

{ny.replaceFirst(/^(?i)(The|A|An)\s((?:.+(?=.+\(\d{4}))|(?:.+))/, /$2, $1/)}
e.g. output: Movie, The (2020)
vs

Code: Select all

{ny.replaceFirst(/^(?i)(The|A|An)\s(.+)/, /$2, $1/)}
e.g. output: Movie (2020), The

Regular expression:
(abc) capture group
\1 backreference to group #1 ($1 in Filebot)
. Dot. Matches any character except line breaks.
+ Quantifier. Match 1 or more of the preceding token.

Re: help with {n.replaceFirst(/^(?i)(The|A|An)\s(.+)/, /\$2, \$1/)}

Posted: 11 Jan 2020, 08:12
by rednoah
Just using n.sortName() is an easy option.