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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T14:48:29+00:00 2026-05-17T14:48:29+00:00

Problem There is a program file that contains the following code snippet at some

  • 0

Problem

There is a program file that contains the following code snippet at some point in the file.

...

food($apples$ , $oranges$ , $pears$ , $tomato$){
  ...
}

...

This function may contain any number of parameters but they must be strings separated by commas. All the parameter strings are lowercase words.

I want to be able to parse out each of the parameters using a regular expression. For example the resulting list in python would be as follows:

["apples", "oranges", "pears", "tomato"]

Attempted Solution

Using the python RE module, I was able to achieve this by breaking the problem into two parts.

  1. Find the function in the code and extract the list of parameters.

    plist = re.search(r'food\((.*)\)', programString).group(1)
    
  2. Split the list using another regular expression.

    params = re.findall(r'[a-z]+', plist)
    

Question

Is there anyway I could achieve this with one regular expression instead of two?

Edit

Thanks to Tim Pietzcker’s answer I was able to find some related questions:

  1. Python regular expressions – how to capture multiple groups from a wildcard expression?
  2. Which regex flavors support captures (as opposed to capturing groups)?
  • 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-17T14:48:29+00:00Added an answer on May 17, 2026 at 2:48 pm

    To answer your question “Can it be done in a single regex?”: Yes, but not in Python.

    If you want to match and capture (individually) an unknown number of matches as in your example, using only a single regular expression, then you need a regex engine that supports captures (as opposed to capturing groups). Only .NET and Perl 6 do this currently.

    So in Python, you either need to do it in two steps (find the entire food(...) function call, and then findall individual matches with a second regex as suggested by Dingo).

    Or use a parser like Paul McGuire’s pyparsing.

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

Sidebar

Related Questions

Given a postscript file that has the following header %!PS-Adobe-3.0 I would like to
I have what seems to be a simple problem that I can't solve myself.
I'm having troubles getting this to work. Basically I have a python program that
Thanks to those who answered my last couple questions, I got the following code
SOLVED see Edit 2 Hello, I've been writing a Perl program to handle automatic
I am writing an application that reads in a large number of basic user
I have a Java application hosted on a remote tomcat instance that executes a
I have this very huge XML file of size 2.8GB. This is Polish Wikipedia's
Maybe it's something I'm doing wrong. I'm just learning Linq because I'm bored. And
We are trying to split up our monolithic EXE into a combination of an

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.