import re
regex = re.compile(r"(E|e|Ep|ep|episode|Episode) ?0*(?<sequencenumber>\d+)\D", flags=re.MULTILINE)
test_str = ("[Erai-raws] One Piece - 004 [1080p]\n"
"[Erai-raws] One Piece - 006 [1080p]\n"
"[Erai-raws] One Piece - 009 [1080p]\n"
"[Erai-raws] One Piece - 037 [1080p]\n"
"[Erai-raws] One Piece - 082v2 [1080p]\n"
"[Erai-raws] One Piece - 0983 [1080p][Multiple Subtitle][1E6E13DB]\n"
"[Erai-raws] One Piece - 0988 [1080p][Multiple Subtitle][4311FFE4]\n"
"[Erai-raws] One Piece - 0993 [1080p][Multiple Subtitle][7E9CB1A1]\n"
"[Erai-raws] One Piece - 0996 [1080p][Multiple Subtitle][3AE37DDB]\n"
"[Erai-raws] One Piece - 1020 [1080p][Multiple Subtitle][E9F69D2D]\n"
"[Erai-raws] One Piece - 1064 [1080p][3D04E09D]")
matches = regex.finditer(test_str)
for match_num, match in enumerate(matches, start=1):
print(f"Match {match_num} was found at {match.start()}-{match.end()}: {match.group()}")
for group_num, group in enumerate(match.groups(), start=1):
print(f"Group {group_num} found at {match.start(group_num)}-{match.end(group_num)}: {group}")
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