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