I would like to create a regex expression that matches all possible episode numbering formats from a tv show file format.
The related post here, only matches in the following formats: S1E1, S11E1, S1E11, S11E11.
I would like to match the following formats: episode01, episode 01, episode1, episode 1, e01, e1, e0102, e01-02, e01e02, e01-e02, e111, e001002, e1-e2, e001-e002.
I currently have this regex which matches most but not all of the list of examples.
(?:(?<=e)|(?<=episode)|(?<=episode[\.\s]))(\d{1,2})|((?<=-)\d{1,2})
The one it does not match is when there are two episodes directly after another e0102
should match 01
and 02
.
You can find the regex example with test cases here
As per your comment, I went by following assumptions:
Therefor, try the following:
e(?:pisode)?\s*(\d{1,3}(?!\d)|\d\d\d??)(?:-?e?(\d{1,3}))?(?!\d)
Here is an online demo. You'll notice I added some more samples to showecase the above assumptions.
e(?:pisode)?\s*
- Match either 'e' or 'episode' with 0+ trailing whitespace characters;(\d{1,3}(?!\d)|\d\d\d??)
- A 1st capture group to catch 1-3 digits if not followed by any other digit or two digits;(?:-?e?(\d{1,3}))?
- An optional non-capture group with a nested 2nd capture group looking for optional hyphen and literal 'e' with trailing digits (1-3);(?!\d)
- There is no trailing digit left.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With