Page 1 of 1

How to pad a single digit in Title Name?

Posted: 21 Apr 2024, 15:58
by DavidRTurner
I want to pad my series' titles with a leading zero, when the title is "Episode x" (just one digit, ie. 1-9).
My format expression covers this for Season/Episode, but I want to capture "Episode 1" and replace with "Episode 01" in the Title.

Basically, it should be something like:

Code: Select all

{ fn.contains('Episode ' + /(\d{1})\b/ ) ? 'Episode 0' + $1 : fn }
but I cannot find a way to get the backreference working.

Any help appreciated...

Re: How to pad a single digit in Title Name?

Posted: 21 Apr 2024, 17:43
by rednoah
e.g.

Format: Select all

{ 'Episode 1'.replaceAll(/Episode \d/){ it.pad(2) } }

Code: Select all

Episode 01


:idea: The String.pad() helper notably works for any number in any String value:

Format: Select all

{ 'Episode 1'.pad(2) }

Re: How to pad a single digit in Title Name?

Posted: 21 Apr 2024, 19:35
by DavidRTurner
Thanks for the always-quick, red!!!

The example was using the filename, but the TITLE field is of course, what I meant.
I'm now using the simpler

Code: Select all

{t.pad(2)}
which seems to work perfectly for this, and also other cases.