# coding=utf8
# the above tag defines encoding for this document and is for Python 2.x compatibility
import re
regex = r"([ .\w']+?)($|mp3|[s|S]\d{1,}|\(.*\)|[A-Z]{2,}|\W\d{4}\W?.*)"
test_str = ("Better Call Saul S02E03 - Amarillo.mkv\n"
"dexter.New.Blood.mp3.S01E03.mkv\n"
"Rick.and.Morty.S05E01.720p.AMZN.WEBRip.x264-GalaxyTV.mkv\n"
"Black.Widow.mp4\n"
"Dexter.New.Blood.S01E01.mp4\n"
"Radin (2016) VFF [1080p] BluRay x264-PopHD.mkv\n"
"This Is the End 1080p MULTI 2013 BluRay x264.mkv\n"
"[ www.CpasBien.cm ] Marseille.2016.FRENCH.DVDRip.XviD-UTT.avi\n"
"(Complet)Le Pere Noel Est Une Ordure (Divx-Francais).avi\n"
"20.Ans.d.Ecart.2013.FRENCH.BRRIP.XviD-FUZION.avi\n"
"Blade.Runner.2049.2017.VOSTFR.FANSUB.1080p.WEB-DL.H264.AC3-TRUEDUKES.WwW.Torrent9.pe")
matches = re.finditer(regex, test_str, re.MULTILINE)
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