Wrestling with a regex preset

Hey all,

Admittedly, I'm no Regex Grand Pooba, :laughing: I only mess with them occasionally as needed, and I'm running into a fight with one at the moment, that maybe someone else already has more experience with, that could help out.

I'm trying to create a rename preset, that will find all sXXeXX (or eXXX), then replace that with s00eXX (or XXX) where XX is a number incremented by 1 each time, starting at a number that I give it. This is exclusively for renaming series' extras, for Plex, so the series number is always 00. (s00).

For example, I have these files highlighted:

Breaking Bad - S02E01 Deleted Scene - Loading His Gun - [SD 360p x265 640x364] [AAC 2ch].m4v
Breaking Bad - S02E01 Extra - Inside Breaking Bad - [SD 360p x265 640x372] [AAC 2ch].m4v
Breaking Bad - S02E02 Extra - Inside Breaking Bad - [SD 360p x265 640x370] [AAC 2ch].m4v
Breaking Bad - S02E03 Deleted Scene - Reflections - [SD 360p x265 640x366] [AAC 2ch].m4v
Breaking Bad - S02E03 Extra - Inside Breaking Bad - [SD 360p x265 640x370] [AAC 2ch].m4v
Breaking Bad - S02E04 Deleted Scene - Blueberry Muffins - [SD 360p x265 640x366] [AAC 2ch].m4v
Breaking Bad - S02E04 Extra - Inside Breaking Bad - [SD 360p x265 640x370] [AAC 2ch].m4v
Breaking Bad - S02E05 Extra - Inside Breaking Bad - [SD 360p x265 640x368] [AAC 2ch].m4v
Breaking Bad - S02E06 Deleted Scene - Walt's Return - [SD 360p x265 640x364] [AAC 2ch].m4v
Breaking Bad - S02E06 Extra - Inside Breaking Bad - [SD 360p x265 640x368] [AAC 2ch].m4v
Breaking Bad - S02E07 Extra - Inside Breaking Bad - [SD 360p x265 640x368] [AAC 2ch].m4v
Breaking Bad - S02E08 Deleted Scene - The Yearbook - [SD 360p x265 640x364] [AAC 2ch].m4v
Breaking Bad - S02E08 Extra - Inside Breaking Bad - [SD 360p x265 640x366] [AAC 2ch].m4v
Breaking Bad - S02E09 Deleted Scene - Raincheck - [SD 360p x265 640x364] [AAC 2ch].m4v
Breaking Bad - S02E09 Deleted Scene - Waiting For Results - [SD 360p x265 640x364] [AAC 2ch].m4v
Breaking Bad - S02E09 Extra - Inside Breaking Bad - [SD 360p x265 640x366] [AAC 2ch].m4v
Breaking Bad - S02E10 Deleted Scene - Internal Thoughts - [SD 360p x265 640x366] [AAC 2ch].m4v
Breaking Bad - S02E10 Extra - Inside Breaking Bad - [SD 360p x265 640x370] [AAC 2ch].m4v
Breaking Bad - S02E11 Deleted Scene - Baby-proofing - [SD 360p x265 640x366] [AAC 2ch].m4v
Breaking Bad - S02E11 Deleted Scene - Walt's Demonstration - [SD 360p x265 640x364] [AAC 2ch].m4v
Breaking Bad - S02E11 Deleted Scene - Welcome Holly - [SD 360p x265 640x366] [AAC 2ch].m4v
Breaking Bad - S02E11 Extra - Inside Breaking Bad - [SD 360p x265 640x370] [AAC 2ch].m4v
Breaking Bad - S02E12 Extra - Inside Breaking Bad - [SD 360p x265 640x366] [AAC 2ch].m4v
Breaking Bad - S02E13 Deleted Scene - I'll Drive - [SD 360p x265 640x364] [AAC 2ch].m4v
Breaking Bad - S02E13 Deleted Scene - Rescuing Jesse - [SD 360p x265 640x364] [AAC 2ch].m4v
Breaking Bad - S02E13 Extra - Inside Breaking Bad - [SD 360p x265 640x366] [AAC 2ch].m4v

And upon doing a rename, I enter, say, 45, and the result would look like this:

Breaking Bad - S00E45 Deleted Scene - Loading His Gun - [SD 360p x265 640x364] [AAC 2ch].m4v
Breaking Bad - S00E46 Extra - Inside Breaking Bad - [SD 360p x265 640x372] [AAC 2ch].m4v
Breaking Bad - S00E47 Extra - Inside Breaking Bad - [SD 360p x265 640x370] [AAC 2ch].m4v
Breaking Bad - S00E48 Deleted Scene - Reflections - [SD 360p x265 640x366] [AAC 2ch].m4v
Breaking Bad - S00E49 Extra - Inside Breaking Bad - [SD 360p x265 640x370] [AAC 2ch].m4v
Breaking Bad - S00E50 Deleted Scene - Blueberry Muffins - [SD 360p x265 640x366] [AAC 2ch].m4v
Breaking Bad - S00E51 Extra - Inside Breaking Bad - [SD 360p x265 640x370] [AAC 2ch].m4v
etc. ...

The episode number basically needs to just go as high of a number as needed, because with lots of seasons' extras, they can go into the hundreds sometimes.

I've come up with this regex so far, for spotting the sXXeXX:

[sS](\d\d?)[eE](\d\d?)

But from there on out I'm stuck. Having a bit of a hard time doing the replace. :blush:

Anyone have any ideas?

TIA!

Update:

I've gotten to this point now; new find regex:

(.+)[sS](\d\d?)[eE](\d\d?)(.+)

Replace regex:

\1s00e{ARGH!}\4

Where the "{ARGH!}" is where I'm stuck incrementing. :laughing:

You need to combine regex with the Opus rename dialog's sequential numbering option.

Thanks Jon.

Looks like I only needed to add the [#]. :laughing:

For anyone else who may come across this thread, and want the working result, it's this:

Find:

(.+)[sS](\d\d?)[eE](\d\d?)(.+)

Replace:

\1s00e[#]\4

Then just check the Sequential Numbering box, and enter whichever numbers wanted. :thumbsup:

Hey, out of curiosity, if this were to be done outside of Directory Opus, what would be used in place of the [#]? Would it require a non-regex function coded out?

Regular expressions cannot increment numbers across multiple filenames on their own, so how you'd do it outside of Opus would depend on what you were using.

@GeekDrop

Nice to see someone using regex presets. I love those.

A couple suggestions:

  • since TR1 regex doesn't support the inline case-insensitive flag (?i), to simplify your character classes such as [eE] you can just uncheck the "Case Sensitive" box in the Opus preset, and just type "e" instead of [eE]

  • I'm sure you're aware of \d{1,2} as an alternative idiom to \d\d? (mentioning it in passing, no benefit in this case)

  • I notice you have a naming convention with some interesting metadata. You might want to check out the file name database script which would enable you to display that information (e.g. show name, bit rate etc) in Opus columns -- you can then sort etc.

Thanks Playful! Always love picking up useful tips. :smiley: