I have tried a written a code like so re.findall(r'[A-Z]{3}[a-z][A-Z]{3}',string) to find the solution for this python challenge http://www.pythonchallenge.com/pc/def/equality.html it seems so hard to figure out. I'm getting 527 matches and none takes me to the next level. Help or close hints will be appreciated

You can perhaps add the condition that there is no uppercase letter before the first 3 ones or after the 3 last ones.

I tried that. I did a '.+{3}' on both sides

I have tried a written a code like so re.findall(r'[A-Z]{3}[a-z][A-Z]{3}',string) to find the solution for this python challenge

Add [^A-Z] in each end.

[^A-Z] # any character except a capital letter
[^A-Z] # ensures that there isn't a 4th uppercase letter

And parentes () around [a-z],so it's a capturing group.
This is capturing group 1 with re.findall().
You don't specific group call like you do with re.search().
re.findall() just return output from capturing group 1.

>>> import re
>>> s = 'Python is fun'
>>> re.findall(r'\w.*(fun)', s)
['fun']
>>> re.search(r'\w.*(fun)', s).group(0) #or just .group()
'Python is fun'
>>> re.search(r'\w.*(fun)', s).group(1)
'fun'

Thanks snippsat but this didn't help me solve the problem. by having a capturing group ([a-z]), I still got 175 matches and they were just single letters

You have only one letter in group.

I don't want that. I think the challenge expects that I get 7 characters with one small letter at the center then 3 on both ends

by having a capturing group ([a-z]), I still got 175 matches and they were just single letters

Did you place [^A-Z] as i told you?
Then it should look like this [^A-Z][A-Z]{3}([a-z])[A-Z]{3}[^A-Z]

wow!! I was doing it wrong all the while. Thanks a lot snippsat

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.