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

The Archive Base Latest Questions

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

Sorry about the title, I couldn’t come up with a clean way to ask

  • 0

Sorry about the title, I couldn’t come up with a clean way to ask my question.

In Python I would like to match an expression ‘c[some stuff]t’, where [some stuff] could be any number of consecutive a’s, b’s, or c’s and in any order.

For example, these work:
‘ct’, ‘cat’, ‘cbbt’, ‘caaabbct’, ‘cbbccaat’

but these don’t:
‘cbcbbaat’, ‘caaccbabbt’

Edit: a’s, b’s, and c’s are just an example but I would really like to be able to extend this to more letters. I’m interested in regex and non-regex solutions.

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

    Not sure how attached you are to regex, but here is a solution using a different method:

    from itertools import groupby
    
    words = ['ct', 'cat', 'cbbt', 'caaabbct', 'cbbccaat',  'cbcbbaat', 'caaccbabbt']
    for w in words:
        match = False
        if w.startswith('c') and w.endswith('t'):
            temp = w[1:-1]
            s = set(temp)
            match = s <= set('abc') and len(s) == len(list(groupby(temp)))
        print w, "matches" if match else "doesn't match"
    

    The string matches if a set of the middle characters is a subset of set('abc') and the number of groups returned by groupby() is the same as the number of elements in the set.

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

Sidebar

Related Questions

Sorry about the question title, but I couldn't find a more appropriate way to
Sorry about the title, I couldn't think of a better way to describe the
[Sorry about the clumsy title - I couldn't figure out the best way to
Sorry about the poorly articulated title, I couldn't think of a title that would
Sorry about the title - I couldn't figure out a way to phrase it.
I'm sorry about the ambiguous title - I couldn't come up with an explanation
First, sorry for the vague question title. I couldn't come up with a more
Sorry about the rubbish question title. I have a table SET_DEFINITIONS like this: SETKEY
Sorry about the extremely vague question title (any suggestions for improvements welcome) I have
Sorry about the wording for my question title. I have a basic HTML anchor

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.