How to pad a single digit in Title Name?

All about user-defined episode / movie / file name format expressions
Post Reply
DavidRTurner
Power User
Posts: 89
Joined: 01 Feb 2014, 16:59

How to pad a single digit in Title Name?

Post 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...
User avatar
rednoah
The Source
Posts: 23021
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

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

Post 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) }
:idea: Please read the FAQ and How to Request Help.
DavidRTurner
Power User
Posts: 89
Joined: 01 Feb 2014, 16:59

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

Post 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.
Post Reply