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 8662347
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T16:43:02+00:00 2026-06-12T16:43:02+00:00

I have this string circle,4.5 square,3.1 circle,2.0 triangle,4.7,4.9 square,4.1 circle,4.3 Lets say I want

  • 0

I have this string

circle,4.5
square,3.1
circle,2.0
triangle,4.7,4.9
square,4.1
circle,4.3

Lets say I want to capture The name of the shape and the two numbers next to it. I’ve tried this and will comment about the issue i have inside it:

>>> ma = re.search(r"(\w+)[,(\d+.\d+)]+", "Triangle,3.4,1.2")
>>> ma.group()
'Triangle,3.4,1.2'
>>> ma.group(1)
'Triangle'
>>> ma.group(2)  ##Why is this happening ???
Traceback (most recent call last):
  File "<pyshell#29>", line 1, in <module>
    ma.group(2)
IndexError: no such group

I guess i can’t put capturing groups inside square brackets ?

  • 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-06-12T16:43:03+00:00Added an answer on June 12, 2026 at 4:43 pm

    Square brackets are special; they mark all characters inside of them as a character group. You are asking to match either a number (\d), a , comma, a . full stop, a ( opening parenthesis or a ) closing parenthesis. In other words, the opening and closing parenthesis are part of the matched characters, not denoting a capturing group.

    You don’t need to use a character class at all here, you are looking for a more specific pattern of number, follewed by a full stop followed by another number. Use a non-capturing group ((?:...)) to group the number format together with the comma to match repeating groups of numbers:

    r"(\w+)(?:,(\d+.\d+))+"
    

    Unfortunately, this still won’t capture more than one group for you; regular expressions will never produce a variable number of groups. We’ve defined only two group here, so that’s all we get:

    >>> import re
    >>> ma = re.search(r"(\w+)(?:,(\d+.\d+))+", "Triangle,3.4,1.2")
    >>> ma.groups()
    ('Triangle', '1.2')
    

    See Regex question about parsing method signature and python regex repetition with capture question for other SO questions that ran into this limitation.

    Your format is actually very simple, and you’d be much better off not using regular expressions at all. Simply split by the , comma and be done with it:

    >>> "Triangle,3.4,1.2".split(',')
    ['Triangle', '3.4', '1.2']
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this string 2012-06-27 16:17:06 and I want to convert it to GMT
I have this String String criteria=ESS.(BVA4+BVA5)+(-(DIESE.(BVM5+BVM6))); I want to put validations on it. It
I have this string in php i want to skip the ppattern ------------------------------------------ FROM:Andy;
I have this string in R: numbers <- 4 4956 1.00e-09 50.9 1.244 47.1
We have this string: according to posts #4,#5 and #6 the word... I want
Suppose that I have a catalog with shapes (Square, Circle, Triangle) and colors (red,
Lets say I have a MovieClip called Box, and String is actually 'box' just
I have this string: 123-456-7 I need to get this string: 1234567 How I
I have this string: \Blah \'Blah\' Blah\ . There is another string inside it.
I have this string stored in a variable: IN=bla@some.com;john@home.com Now I would like to

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.