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

  • Home
  • SEARCH
  • 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 6137509
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T17:44:10+00:00 2026-05-23T17:44:10+00:00

using python3’s regex capabilities, is it possible to capture variable numbers of capture blocks,

  • 0

using python3’s regex capabilities, is it possible to capture variable numbers of capture blocks, based on the number of the repetitions found? for instance, in the following search strings, i want to capture all the digit strings with the same regex.

search string 1(trying to capture: 89, 45):

zzz89zzz45.mp3

search string 2(trying to capture: 98, 67, 89, 45):

zzz98zzz67zzz89zzz45.mp3

search string 3(trying to capture: 98, 67, 89, 45, 55, 111):

zzz98zzz67zzz89zzz45vdvd55lplp111.mp3

the following regex will match all the repetitions, though all the values are not available for later use(only 1 digit string is captured):

((\d+)\D*)*\.mp3$

the other 2 options are writing a different regex for every case, or use findall(). Is there a way to adjust the above regex in order to capture every digit string for later use with various numbers of repetitions using just regex facilities, or to do this in python3, are you forced to use findall()?

  • 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-23T17:44:10+00:00Added an answer on May 23, 2026 at 5:44 pm

    Most or all regular expression engines in common use, including in particular those based on the PCRE syntax (like Python’s), label their capturing groups according to the numerical index of the opening parenthesis, as the regex is written. So no, you cannot use capturing groups alone to extract an arbitrary, variable number of subsequences from a string.

    The closest you can get (as far as I know) is to manually write out a certain number of capturing groups, something like this:

    s = ...
    res = re.match(r'\D*' + 25 * r'(\d+)\D+')
    numbers = [r for r in res.groups() if r is not None]
    

    This will get you up to 25 groups of digits. If you need more, replace 25 with some higher number.

    I wouldn’t be surprised if this were less efficient than the iterative approach with findall(), although I haven’t tested it.

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

Sidebar

Related Questions

My python2 script uploads files nicely using this method but python3 is presenting problems
Using python and wsgiref.handlers, I can get a single variable from a form with
I'm converting a single module using 2to3. test_lib2to3.py is in /Library/Frameworks/Python.framework/Versions/3.1/lib/python3.1/test/test_lib2to3.py File to be
Based on my understanding of Python's data model , and specifically the subsection Instance
Using Python, I'd like to compare every possible pair in a list. Suppose I
I'm using asynchat and trying to use python3. getting this error: error: uncaptured python
I'm attempting to map libpcap using ctypes to python3.2 and I'm having a problem
Im planing to do some GUI development using pyqt4 pykde and python3.1 on Kubuntu
Using Python I want to be able to draw text at different angles using
Using python 2.4 and the built-in ZipFile library, I cannot read very large zip

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.