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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T09:44:31+00:00 2026-05-25T09:44:31+00:00

I am working on a program with regexes, I have to filter them but

  • 0

I am working on a program with regexes, I have to filter them but I can’t find out how. I want to match every red,xxxx or xxxx,red expression in my string and put the colors xxxx into a group. Here is my code:

string = "blue,red   red,yellow   blue,yellow   red,green   purple red, ..."
regex = re.compile('(?:red,(?P<redfirst>\w+)|(?P<othercolorfirst>\w+),red)')

Then I write:

for match in regex.finditer(string):
    if match.group('redfirst')!= "None":
        print(match.group("redfirst"))

But I still obtain printing like:

None
yellow
green
None

I dont want the ‘None’ results to appear, I have to skip them in an smart way if possible.
Thanks for help!

EDIT None without quotes doesn’t work either

  • 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-25T09:44:31+00:00Added an answer on May 25, 2026 at 9:44 am
    >>> import re
    >>> regex = re.compile('(?:red,(?P<redfirst>\w+)|(?P<othercolorfirst>\w+),red)')
    
    >>> string = "blue,red   red,yellow   blue,yellow   red,green   purple red, ..."
    
    >>> for matches in regex.finditer(string):
    ...     if matches.group('redfirst'):
    ...         print matches.group('redfirst')
    ...
    yellow
    green
    >>>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to get my program working without boost usage, but can't find an
I have a working program but now I have to use the int argc
I have a working program on eclipse but my professor plans on running it
I have a working program in C++ that generates data for a Mandelbrot Set.
how can i make java program working with multiple languages (frensh, english , arabic
I'm working on a program that processes many requests, none of them reaching more
I have an otherwise working iPhone program. A recent change means that it generates
I have a working program to compute the longest collatz chain in a given
I was given a working FORTRAN program and i have to write C# GUI
I'm trying to get a simple send and receive UDP program working, but I'm

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.