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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T05:12:57+00:00 2026-06-03T05:12:57+00:00

I have a string with a mix of uppercase and lowercase letters. I need

  • 0

I have a string with a mix of uppercase and lowercase letters. I need want to find every lowercase letter that is surronded by 3 uppercase letters and extract it from the string.

For instance ZZZaZZZ I want to extract the a in the previous string.

I have written a script that is able to extract ZZZaZZZ but not the a alone. I know I need to use nested regex expressions to do this but I can not wrap my mind on how to implement this. The following is what I have:

import string, re                                                                                                                                                                

if __name__ == "__main__":                                                                                                                                                       

    #open the file                                                                                                                                                               
    eqfile = open("string.txt")                                                                                                                                                
    gibberish = eqfile.read()                                                                                                                                                    
    eqfile.close()                                                                                                                                                               

    r = re.compile("[A-Z]{3}[a-z][A-Z]{3}")                                                                                                                                      
    print r.findall(gibberish)           

EDIT:
Thanks for the answers guys! I guess I should have been more specific. I need to find the lowercase letter that is surrounded by three uppercase letters that are exactly the same, such as in my example ZZZaZZZ.

  • 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-03T05:12:59+00:00Added an answer on June 3, 2026 at 5:12 am

    You are so close! Read about the .group* methods of MatchObjects. For example, if your script ended with

    r = re.compile("[A-Z]{3}([a-z])[A-Z]{3}")
    print r.match(gibberish).group(1)
    

    then you’d capture the desired character inside the first group.

    To address the new constraint of matching repeated letters, you can use backreferences:

    r = re.compile(r'([A-Z])\1{2}(?P<middle>[a-z])\1{3}')
    m = r.match(gibberish)
    if m is not None:
        print m.group('middle')
    

    That reads like:

    1. Match a letter A-Z and remember it.
    2. Match two occurrences of the first letter found.
    3. Match your lowercase letter and store it in the group named middle.
    4. Match three more consecutive instances of the first letter found.
    5. If a match was found, print the value of the middle group.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have string that look like Array that fetched from other webservice like this
I have string that displays UTF-8 encoded characters, and I want to convert it
I have a list of strings that can contain a letter or a string
I have a list of String characters, They are mix characters that includes special
Is it possible to mix JPQL and CriteriaQuery ? I have a String that
Hi I have a mix type of string. i want to remove special symbol
I have two strings in a java program, which I want to mix in
I have string as abvd.qweqw.sdfs.a=aqwrwewrwerrew . I need to parse this string and get
i have string stored in python variables, and i am outputting a html that
I have a .NET application that is shared to around 30 different computers, (mix

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.