Regular Expressions 101

Community Patterns

Distinguish torrent files (series vs movies) with episode numbers

1

Regular Expression
Python

r"
^ # get the title of this movie or series (?P<title> [-\w',\"]+ # match separator to later replace into correct title (?P<separator> [ .-] ) # note this *must* be lazy for the engine to work ltr not rtl (?: [-\w',\"]+\2 )*? ) # start of movie vs series check (?: # if this is an episode, lets match the season # number and episode number. if not, the year # of the movie (?: # make sure this is not just a number in the title followed by our separator. # like, iron man 3 2013 or my.fictional.24.series (?! \d+ \2) # now try to match the season number (?: s (?: eason \2? )? )? (?P<season> \d\d? ) # also try to match the episode number (?: e (?: pisode \2? )? | x |-e)? (?P<episode> \d\d? )? | # this is likely a movie, match the year (?P<year> [(\]]?\d{4}[)\]]? ) ) # make sure this ends with the separator, otherwise we # might be in the middle of something like "1080p" # added special case to handle [title][year][season] as tv show (?=\2(?!(s(?: eason \2? )?[0-9]))) | # if we get here, this is likely still a movie. # match until one of the keywords (?= BOXSET | XVID | DIVX | LIMITED | MKV | UNRATED | PROPER | DTS | AC3 | AAC | BLU[ -]?RAY | HD(?:TV|DVD) | (?:DVD|B[DR]|WEB)RIP | \d+p | [hx]\.?26[45] ) )
"
gimx

Description

a modified verison of this awesome regex https://regex101.com/library/yP4bY4 by author firas dib that includes a capture group for episode numbers in addition to season numbers.

Submitted by SethMacKayChandler - 15 days ago (Last modified 14 days ago)