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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T07:06:05+00:00 2026-06-05T07:06:05+00:00

I am doing the Python challenge and while I figured out the answer to

  • 0

I am doing the Python challenge and while I figured out the answer to a puzzle, I did it in a hacky, not-very-good way. Upon advancing I was able to see the solution which is:

string1 = open('text.txt').read()
print ''.join(re.findall('[^A-Z][A-Z]{3}([a-z])[A-Z]{3}[^A-Z]', string1))

I messed with this for a while, removing a caret here and seeing what happens, changing a braced group there. However, I just cant wrap my head around why this works. Could anyone explain it in a easy to understand way?

Thank you!

  • 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-05T07:06:06+00:00Added an answer on June 5, 2026 at 7:06 am

    I compiled the pattern as verbose to include inline comments:

    pat = re.compile('''
        [^A-Z]    # any character except a capital letter
        [A-Z]{3}  # three capital letters
        (         # the beginning of a capturing group
        [a-z]     # one lowercase letter 
        )         # the end of the group
        [A-Z]{3}  # three capital letters
        [^A-Z]    # any character except a capital letter
        ''', re.VERBOSE)
    

    Demo:

    >>> re.findall(pat, 'AAAAaBBBbBBBBzzZZZxXXXyYYYYwWWWvABCn')
    ['x', 'v']
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm not used to doing things the python way yet, but I'm almost certain
What is the best way of doing this in Python? for (v = n
While doing some random experimentation with a factorial program in C, Python and Scheme.
Is there a better way of doing this in python 3: point, edges =
I am doing Python challenge in Ruby. I need to read the file contents
First time doing Python in a while, and I'm having trouble doing a simple
While going through one of the problems in Python Challenge , I am trying
Is there a more concise way of doing this in Python?: def toDict(keys, values):
While doing this in python: tp = curses.textpad.Textbox(stdscr, insert_mode=True) text = tp.edit() I get
I'm sure there's an elegant way of doing this in Python (or at a

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.