Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 261215
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T22:24:48+00:00 2026-05-11T22:24:48+00:00

Is there a way to match a pattern ( e\d\d ) several times, capturing

  • 0

Is there a way to match a pattern (e\d\d) several times, capturing each one into a group? For example, given the string..

blah.s01e24e25

..I wish to get four groups:

1 -> blah
2 -> 01
3 -> 24
4 -> 25

The obvious regex to use is (in Python regex:

import re
re.match("(\w+).s(\d+)e(\d+)e(\d+)", "blah.s01e24e25").groups()

..but I also want to match either of the following:

blah.s01e24
blah.s01e24e25e26

You can’t seem to do (e\d\d)+, or rather you can, but it only captures 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 a single regex because I have multiple patterns to match TV episode filenames, and do not 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

..and so on for numerous other patterns.

Another thing to complicate matters – I wish to store these regexs in a config file, so a solution using multiple regexs and function calls is not desired – but if this proves impossible I’ll just allow the user to add simple regexs

Basically, is there a way to capture a repeating pattern using regex?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T22:24:48+00:00Added an answer on May 11, 2026 at 10:24 pm

    After thinking about the problem, I think I have a simpler solution, using named groups.

    The simplest regex a user (or I) could use is:

    (\w+\).s(\d+)\.e(\d+)
    

    The filename parsing class will take the first group as the show name, second as season number, third as episode number. This covers a majority of files.

    I’ll allow a few different named groups for these:

    (?P<showname>\w+\).s(?P<seasonnumber>\d+)\.e(?P<episodenumber>\d+)
    

    To support multiple episodes, I’ll support two named groups, something like startingepisodenumber and endingepisodenumber to support things like showname.s01e01-03:

    (?P<showname>\w+\)\.s(?P<seasonnumber>\d+)\.e(?P<startingepisodenumber>\d+)-(?P<endingepisodenumber>e\d+)
    

    And finally, allow named groups with names matching episodenumber\d+ (episodenumber1, episodenumber2 etc):

    (?P<showname>\w+\)\.
    s(?P<seasonnumber>\d+)\.
    e(?P<episodenumber1>\d+)
    e(?P<episodenumber2>\d+)
    e(?P<episodenumber3>\d+)
    

    It still requires possibly duplicating the patterns for different amounts of e01s, but there will never be a file with two non-consecutive episodes (like show.s01e01e03e04), so using the starting/endingepisodenumber groups should solve this, and for weird cases users come across, they can use the episodenumber\d+ group names

    This doesn’t really answer the sequence-of-patterns question, but it solves the problem that led me to ask it! (I’ll still accept another answer that shows how to match s01e23e24...e27 in one regex – if someone works this out!)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a way to pattern match in F# so that it will check
Is there a quick way to find every match of a regular expression in
is there a way to treat a section of your regex string 'as is'?
What is the fastest way to check if a string matches a certain pattern?
Is there any feasible way of using generics to create a Math library that
Is there way in next piece of code to only get the first record?
is there way thats i can preselect an item when the page loads or
Is there a way to enforce constraint checking in MSSQL only when inserting new
Is there any way to check whether a file is locked without using a
Is there a way to find the name of the program that is running

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.