Is there a way to map a pattern ( e\d\d ) several times by capturing each of them in a group? For example, given the string ..
blah.s01e24e25
.. I want to get four groups:
1 -> blah 2 -> 01 3 -> 24 4 -> 25
Obvious regex to use (in Python regex:
import re re.match("(\w+).s(\d+)e(\d+)e(\d+)", "blah.s01e24e25").groups()
.. but I also want to match one of the following:
blah.s01e24 blah.s01e24e25e26
It seems you cannot do (e\d\d)+ , or rather you can, but only fix the last occurrence:
>>> re.match("(\w+).s(\d+)(e\d\d){2}", "blah.s01e24e25e26").groups() ('blah', '01', 'e25') >>> re.match("(\w+).s(\d+)(e\d\d){3}", "blah.s01e24e25e26").groups() ('blah', '01', 'e26')
I want to do this in one regex, because I have several patterns to match the episode names of TV episodes and I donβt want to duplicate each expression to handle multiple episodes:
\w+\.s(\d+)\.e(\d+) # matches blah.s01e01 \w+\.s(\d+)\.e(\d+)\.e(\d+) # matches blah.s01e01e02 \w+\.s(\d+)\.e(\d+)\.e(\d+)\.e(\d+) # matches blah.s01e01e02e03 \w - \d+x\d+ # matches blah - 01x01 \w - \d+x\d+\d+ # matches blah - 01x01x02 \w - \d+x\d+\d+\d+ # matches blah - 01x01x02x03
.. etc. for many other models.
One more thing that complicates matters is that I want to save these regular expressions in a configuration file, so a solution using several regular expressions and function calls is not required, but if this is not possible, I just let the user add simple regular expressions
Basically, is there a way to capture a repeating pattern using a regular expression?