Regex Help
#1
I am creating a python script that won't be an addon for XBMC/Kodi but will help create efficiency for my HTPC set up by determining if the file is a TV Show or Movie. I am new to regular expressions and this is the first one I have created. I want it to grab the show/movie name, the year if it exists and the season and episode information in two different formats (SxxExx or xxxx or xxx). This information will be used later to query a webservice.

Here is my regular expression I have been testing using the online regular expression tester regex101.com

PHP Code:
(?P<ShowName>.*)#Show Name
(
   [ (
_.]
   (
       (?=\
d{4,4}) #If after the show name is a year
          
(?P<ShowYear>\d{4})  # Get the show year
          
# Else no year in the file name then just grab the name
          
(?P<otherShowName>.*) # Grab Show Name
          
(?=S\d{1,2}E\d{1,2}) # If the Season Episode patterns matches SX{1,2}EX{1,2}, Then
             
S(?P<Season>\d{1,2})E(?P<Episode>\d{1,2}) #Get the season and Episode information
             
# Else
             
(?P<Alt_S_E>\d{3,4}) # Get the season and Episode that looks like 211
   
)
|$) 

Here is my test set I have been using:
  • archer.2009.S04E13
  • space 1999 1975
  • Space: 1999 (1975)
  • Space.1999.1975.S01E01
  • space 1999.(1975)
  • The.4400.204.mkv
  • space 1999 (1975)
  • Teen.wolf.S04E12.HDTV.x264
  • Se7en.(1995).avi
  • How to train your dragon 2
  • Se7en
  • 10,000BC (2010)
  • 10,000 b.c. 2010
  • v.2009.S01E13.the.title.avi

I am having trouble with getting the expression to return the information of the following names from the data set
  • Space.1999.1975.S01E01
  • archer.2009.S04E13
  • How to train your dragon 2
  • Se7en
  • v.2009.S01E13.the.title.avi

For the archer filename it returns the showname with the year appended to the end of it (e.g. showname = "archer.2009"). Samething goes for "v.2009...." and "Space.1999.1975"
The regex will not return anything for "how to train your dragon 2". Same thing goes for "Se7en".

So how can I modify this regex to include the last few scenarios I forsee? I think I have reached my limit of understanding as I'm still learning this stuff and its pretty confusing.
Image
Reply

Logout Mark Read Team Forum Stats Members Help
Regex Help0