# coding=utf8
# the above tag defines encoding for this document and is for Python 2.x compatibility
import re
regex = r"(.+?)[\.\s](?:(?:(\d{4})[\.\s])(S\d{1,2}(?:E\d{1,2})?)|(?:(\d{4})[\.\s])|(S\d{1,2}(?:E\d{1,2}(?:\-E?\d{1,2})?)?)|(?:720p|1080p))[\.\s]?(.*)[\.\s]"
test_str = ("Maze.Runner.The.Scorch.Trials.2015.NORDiC.REMUX.BluRay.1080p.AVC.DTS-HD.MA7.1-iRL\n"
"Get.Santa.2014.DKsubs.1080p.BluRay.x264-GenX\n"
"Two.Step.2014.Custom.DKsubs.1080p.WEB-DL.h264-SUBLiME\n"
"Heroes.Reborn.S01E10.Retail.DKsubs.720p.HDTV.x264-RAPiDCOWS\n"
"The.Transporter.Refueled.2015.DKSUBS.1080p.BluRay.x264-iRL\n"
"Maze.Runner.The.Scorch.Trials.2015.DKSUBS.1080p.BluRay.x264-iRL\n"
"Minority.Report.S01E05.Retail.DKsubs.720p.HDTV.x264-RAPiDCOWS\n"
"Quantico.S01E04.Custom.DKsubs.720p.WEB-DL.x264-RAPiDCOWS\n"
"The.Flash.2014.S02E07.Custom.DKsubs.720p.WEB-DL.x264-RAPiDCOWS\n"
"The.Librarians.2014.S02E02.Custom.DKsubs.720p.HDTV.x264-RAPiDCOWS\n"
"Ant.Man.2015.DKSUBS.REMUX.BluRay.1080p.AVC.DTS-HD.MA7.1-iRL\n"
"The.Blacklist.S03E08.Retail.DKsubs.720p.WEBRip.H.264-RAPiDCOWS\n"
"Limitless.S01E09.Custom.DKsubs.720p.HDTV.x264-NGSerier\n"
"Noble.2014.Custom.DKsubs.1080p.BluRay.x264-ROYAL\n"
"The.Transporter.Refueled.2015.DKSUBS.720p.BluRay.x264-iRL\n"
"Ant.Man.2015.DKSUBS.1080p.BluRay.x264-iRL\n"
"Hitman.Agent.47.2015.NORDiC.REMUX.BluRay.1080p.AVC.DTS-HD.MA.7.1-iRL\n"
"The.Bastard.Executioner.S01E10.Retail.DKsubs.720p.WEB-DL.H.264-RAPiDCOWS\n"
"Homeland.S05E07.Retail.DKsubs.720p.WEB-DL.H.264-RAPiDCOWS\n"
"Everest.2015.DKSUBS.1080p.WEB-DL.h264-iRL\n"
"Boulevard.2014.RETAiL.DKsubs.1080p.BluRay.x264-PUNKTUM\n"
"Gotham.S02E09.Custom.DKsubs.720p.HDTV.x264-NGSerier\n"
"Blindspot.S01E09.Custom.DKsubs.720p.HDTV.x264-NGSerier\n"
"Arrow.S04E06.Custom.DKsubs.720p.WEB-DL.x264-RAPiDCOWS\n"
"Hitman.Agent.47.2015.DKSUBS.1080p.BluRay.x264-iRL\n"
"The.Walking.Dead.S06E06.Custom.DKsubs.720p.HDTV.x264-NGSerier\n"
"Heist.2015.Custom.DKsubs.1080p.WEB-DL.h264-SUBLiME\n"
"Steel.Dawn.1987.REMASTERED.720p.BluRay.x264-VETO\n"
"Get.Santa.2014.DKsubs.720p.BluRay.x264-GenX\n"
"The.Flash.2014.S02E07.Custom.DKsubs.1080p.WEB-DL.x264-RAPiDCOWS\n"
"Summer.with.Monika.1953.1080p.BluRay.x264-SADPANDA\n"
"Back.In.Time.2015.Retail.DKsubs.1080p.BluRay.x264-RAPiDCOWS\n"
"Heartbreakers.2001.1080p.BluRay.x264-SiNNERS\n"
"Heartbreakers.2001.720p.BluRay.x264-SiNNERS\n"
"Larry.Gaye.2015.720p.BluRay.x264-NOSCREENS\n"
"Summer.Interlude.1951.1080p.BluRay.x264-SADPANDA\n"
"Summer.Interlude.1951.720p.BluRay.x264-SADPANDA\n"
"Eight.Men.Out.1988.1080p.BluRay.x264-SiNNERS\n"
"Eight.Men.Out.1988.720p.BluRay.x264-SiNNERS\n"
"Wall.Street.1987.REMASTERED.1080p.BluRay.x264-SADPANDA\n"
"Wall.Street.1987.REMASTERED.720p.BluRay.x264-SADPANDA\n"
"Ikiru.1952.1080p.BluRay.x264-SiNNERS\n"
"Ikiru.1952.720p.BluRay.x264-SiNNERS\n"
"Fairy.Tale.A.True.Story.1997.1080p.BluRay.x264-USURY\n"
"Transformers.Age.of.Extinction.2014.Retail.DKsubs.REMUX.1080p.BluRay.AVC.TrueHD.Atmos7.1-RAPiDCOWS\n"
"Fairy.Tale.A.True.Story.1997.720p.BluRay.x264-USURY\n"
"Minions.2015.SWEDiSH.REPACK.720p.BluRay.x264-BLUEYES\n"
"Bronson.2008.PROPER.1080p.BluRay.x264-SADPANDA\n"
"Closely.Observed.Trains.1966.1080p.BluRay.x264-HD4U\n"
"Bronson.2008.PROPER.720p.BluRay.x264-PHOBOS\n"
"Closely.Observed.Trains.1966.720p.BluRay.x264-HD4U\n"
"Criminal.Activities.2015.720p.WEB-DL.DD5.1.H.264-PLAYNOW.mkv\n"
"Bones.S11E05.Retail.DKsubs.720p.HDTV.x264-RAPiDCOWS\n"
"Steve.Jobs.The.Man.in.the.Machine.2015.Retail.DKsubs.720p.BluRay.x264-RAPiDCOWS\n"
"Steve.Jobs.The.Man.in.the.Machine.2015.Retail.DKsubs.1080p.BluRay.x264-RAPiDCOWS\n"
"Ted.2.2015.EXTENDED.1080p.BluRay.x264-DRONES\n"
"Minions.2015.SWEDiSH.720p.BluRay.x264-BLUEYES\n"
"Ted.2.2015.EXTENDED.720p.BluRay.x264-DRONES\n"
"Sandheden.Om.Maend.2010.DANiSH.720p.BluRay.x264-BLUEYES\n"
"Best.of.Enemies.2015.DOCU.1080p.BluRay.x264-PSYCHD\n"
"Best.of.Enemies.2015.DOCU.720p.BluRay.x264-PSYCHD\n"
"Ant-Man.2015.3D.1080p.BluRay.x264-SPRiNTER\n"
"Nosferatu.1922.REMASTERED.1080p.BluRay.x264-GHOULS\n"
"6.Ways.To.Sundown.2015.720p.BluRay.x264-PFa\n"
"Cats.Eye.1985.Retail.DKsubs.1080p.BluRay.x264-RAPiDCOWS\n"
"The.Transporter.Refueled.2015.1080p.BluRay.x264-GECKOS\n"
"Noble.2014.Custom.DKsubs.720p.BluRay.x264-ROYAL\n"
"Nosferatu.1922.REMASTERED.720p.BluRay.x264-GHOULS\n"
"Ant.Man.2015.DKSUBS.720p.BluRay.x264-iRL\n"
"The.Transporter.Refueled.2015.720p.BluRay.x264-GECKOS\n"
"All.That.Jazz.1979.Retail.DKsubs.1080p.BluRay.x264-RAPiDCOWS\n"
"The.Bastard.Executioner.S01E10.Retail.DKsubs.1080p.WEB-DL.H.264-RAPiDCOWS\n"
"Victoria.2015.1080p.BluRay.x264-USURY\n"
"The.Cabin.In.The.Woods.2012.Retail.DKsubs.1080p.BluRay.x264-RAPiDCOWS\n"
"Sinister.2012.Retail.DKsubs.1080p.BluRay.x264-RAPiDCOWS\n"
"Safe.House.2012.Retail.DKsubs.1080p.BluRay.x264-RAPiDCOWS\n"
"1408.2007.Retail.DKsubs.1080p.BluRay.x264-RAPiDCOWS\n"
"The.Last.Airbender.2010.Retail.DKsubs.1080p.BluRay.x264-RAPiDCOWS\n"
"The.Rewrite.2014.Retail.DKsubs.1080p.BluRay.x264-RAPiDCOWS\n"
"The.Rewrite.2014.Retail.DKsubs.720p.BluRay.x264-RAPiDCOWS\n"
"Maze.Runner.The.Scorch.Trials.2015.DKSUBS.720p.BluRay.x264-iRL\n"
"Last.Knights.2015.Retail.DKsubs.1080p.BluRay.x264-RAPiDCOWS\n"
"Last.Knights.2015.Retail.DKsubs.720p.BluRay.x264-RAPiDCOWS\n"
"Maze.Runner.The.Scorch.Trials.2015.1080p.BluRay.x264-SPARKS\n"
"Maze.Runner.The.Scorch.Trials.2015.720p.BluRay.x264-SPARKS\n"
"Victoria.2015.720p.BluRay.x264-USURY\n"
"Ant-Man.2015.1080p.BluRay.x264-SPARKS\n"
"Ant-Man.2015.720p.BluRay.x264-SPARKS\n"
"Pathfinder.2007.Retail.DKsubs.UNRATED.720p.BluRay.x264-RAPiDCOWS\n"
"Pathfinder.2007.Retail.DKsubs.UNRATED.1080p.BluRay.x264-RAPiDCOWS\n"
"90.Minutes.In.Heaven.2015.1080p.BluRay.x264-DRONES\n"
"90.Minutes.in.Heaven.2015.720p.BluRay.x264-DRONES\n"
"Everest.2015.DKSUBS.720p.WEB-DL.h264-iRL\n"
"Maze.Runner.The.Scorch.Trials.2015.DKSUBS.720p.WEBRip.x264-iRL\n"
"Boulevard.2014.RETAiL.DKsubs.720p.BluRay.x264-PUNKTUM\n"
"The.Stanford.Prison.Experiment.2015.LIMITED.1080p.BluRay.X264-AMIABLE\n"
"Wings.Of.Life.2011.DOCU.1080p.BluRay.x264-HDEX\n"
"The.Stanford.Prison.Experiment.2015.LIMITED.720p.BluRay.X264-AMIABLE\n"
"The.Stanford.Prison.Experiment.2015.1080p.WEB-DL.DD5.1.H264-RARBG\n"
"The.33.2015.1080p.WEB-DL.DD5.1.H264-RARBG")
matches = re.finditer(regex, test_str, re.IGNORECASE)
for matchNum, match in enumerate(matches, start=1):
print ("Match {matchNum} was found at {start}-{end}: {match}".format(matchNum = matchNum, start = match.start(), end = match.end(), match = match.group()))
for groupNum in range(0, len(match.groups())):
groupNum = groupNum + 1
print ("Group {groupNum} found at {start}-{end}: {group}".format(groupNum = groupNum, start = match.start(groupNum), end = match.end(groupNum), group = match.group(groupNum)))
# Note: for Python 2.7 compatibility, use ur"" to prefix the regex and u"" to prefix the test string and substitution.
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for Python, please visit: https://docs.python.org/3/library/re.html