[SNIPPET] Sort Name

All about user-defined episode / movie format expressions
Post Reply
User avatar
rednoah
The Source
Posts: 15958
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

[SNIPPET] Sort Name

Post by rednoah » 31 Jul 2012, 06:15

Sometimes it's useful to put the "The" or an "A" that many movie names begin with (e.g. The Avengers) at the end of the name (Avengers, The) to improve lexical sort order. It's easy to do that in the format via an regular expression replace.


The Avengers => Avengers

Code: Select all

{n.sortName()}
The Avengers => Avengers, The

Code: Select all

{n.sortName('$2, $1')}
Groovy code:

Code: Select all

{n.replaceFirst(/^(?i)(The|A|An)\s(.+)/, /$2, $1/)}
:!: If you mess up the filename like this, FileBot and HTPC software may have trouble making sense of the filename in the future. :!:
:idea: Please read the FAQ and How to Request Help.

jasonsmith
Posts: 1
Joined: 23 May 2019, 15:28

Re: [SNIPPET] Sort Name

Post by jasonsmith » 23 May 2019, 15:31

rednoah wrote:
31 Jul 2012, 06:15
Sometimes it's useful to put the "The" or an "A" that many movie names begin with (e.g. The Avengers) at the end of the name (Avengers, The) to improve lexical sort order. It's easy to do that in the format via an regular expression replace.


The Avengers => Avengers

Code: Select all

{n.sortName( )}
The Avengers => Avengers, The

Code: Select all

{n.sortName('$2, $1')}
Groovy code:

Code: Select all

{n.replaceFirst(/^(?i)(The|A|An)\s(.+)/, /$2, $1/)}
:!: If you mess up the filename like this, FileBot and HTPC software may have trouble making sense of the filename in the future. :!:
i didn't thought this way before, thanks for sharing.myanimelsit mathway birthday wishes

Post Reply