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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T18:40:46+00:00 2026-06-16T18:40:46+00:00

I ran into a small problem using Python Regex. Suppose this is the input:

  • 0

I ran into a small problem using Python Regex.

Suppose this is the input:

(zyx)bc

What I’m trying to achieve is obtain whatever is between parentheses as a single match, and any char outside as an individual match. The desired result would be along the lines of:

['zyx','b','c']

The order of matches should be kept.

I’ve tried obtaining this with Python 3.3, but can’t seem to figure out the correct Regex. So far I have:

matches = findall(r'\((.*?)\)|\w', '(zyx)bc')

print(matches) yields the following:

['zyx','','']

Any ideas what I’m doing wrong?

  • 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-16T18:40:48+00:00Added an answer on June 16, 2026 at 6:40 pm

    From the documentation of re.findall:

    If one or more groups are present in the pattern, return a list of groups; this will be a list of tuples if the pattern has more than one group.

    While your regexp is matching the string three times, the (.*?) group is empty for the second two matches. If you want the output of the other half of the regexp, you can add a second group:

    >>> re.findall(r'\((.*?)\)|(\w)', '(zyx)bc')
    [('zyx', ''), ('', 'b'), ('', 'c')]
    

    Alternatively, you could remove all the groups to get a simple list of strings again:

    >>> re.findall(r'\(.*?\)|\w', '(zyx)bc')
    ['(zyx)', 'b', 'c']
    

    You would need to manually remove the parentheses though.

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

Sidebar

Related Questions

I ran into a small problem with floats that i demonstrate in this fiddle
I've just began learning Python and I've ran into a small problem. I need
I deployed an ASP.NET MVC app using MSDeploy and ran into this problem i
Ran into this error message while trying to select some records off a table.
I ran into a problem using Springsource Tool Suite when writing some groovy scripts
I've ran into one small problem. I am dynamically generating some controls and place
This is the problem I ran into long time ago. I thought I may
I ran into a small roadblock this morning with HandleError. Users are directed properly
In my program, I ran into a problem writing a small number to a
I ran into this problem; it feels like a bug, but it is probably

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.