# coding=utf8
# the above tag defines encoding for this document and is for Python 2.x compatibility
import re
regex = r"(?<Fname>.*\.)(S(?<se>\d{1,2})E(?<ep>\d{2,3}).*|(?<season>S\d{1,2}-S\d{2,3}).*|(?<yr>\d{4}[^p]).*)"
test_str = ("Westworld.S04E05.720p.WEB.h264-KOGi[rarbg]\n"
"Westworld.S04E04.1080p.WEB.H264-CAKES[rarbg]\n"
"For.All.Mankind.S03E08.720p.WEB.h264-KOGi[rarbg]\n"
"Talk.to.Me.2022.1080p.WEBRip.DD5.1.x264-LAMA\n"
"Jules.2023.1080p.AMZN.WEBRip.DD5.1.x264-LAMA\n"
"90.Day.Fiance.UK.S02E12.1080p.HEVC.x265-MeGusta\n"
"Inside.Job.S01-S02.WEBRip.1080p.AAC5.1.x265-SiQ\n"
"Til Death Do Us Part 2023 1080p AMZN WEBRip DD5 1 x264-LAMA\n"
"UFC.Fight.Night.227.Grasso.vs.Shevchenko.2.WEB-DL.H264.Fight-BB[TGx]\n\n\n"
"mIRC does not allow you to retrieve the full match. You can access simple captures but *you cannot access named capture* Well dam, now what?\n\n"
"***Work in progress***\n"
"$replace($1-,$chr(32),$chr(46))\n\n"
";mIRC Alias to test\n"
"alias test1 {\n"
" ;TV\n"
" ;var %s Westworld.S04E05.720p.WEB.h264-KOGi[rarbg]\n\n"
" ;TV Series\n"
" ;var %s Inside.Job.S01-S02.WEBRip.1080p.AAC5.1.x265-SiQ\n\n"
" ;Movie\n"
" var %s A.Million.Miles.Away.2023.1080p.AMZN.WEBRip.DD5.1.x264-LAMA\n\n"
" noop $regex(name, %s,/(?<Fname>.*\\.)(S(?<se>\\d{1,2})E(?<ep>\\d{2,3}).*|(?<season>S\\d{1,2}-S\\d{2,3}).*|(?<yr>\\d{4}[^p]).*)/g)\n"
" if ($len($regml(name,3)) == 5) { Echo -a Movie: Fn: $regml(name,1) Year: $regml(name,3) | halt }\n"
" if (-s isin %s) { Echo -a Series: Fn: $regml(name,1) S: $regml(name,3) }\n"
" else echo -a TV: Fn: $regml(name,1) S: $regml(name,3) EP: $regml(name,4)\n"
"}\n\n"
";mIRC 7zip stuff\n"
"var %eDir $getdir(.tar)\n"
"var %oDir $getdir_Movies\n"
" /run -np \"c:\\Program files\\7-Zip\\7z.exe\" e -aos \" $+ %eDir $+ %s $+ \" *.avi *.mkv *.mp4 -r -o $+ \" $+ %oDir $+ \"")
matches = re.finditer(regex, test_str)
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