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

Edited 2 Years Ago by Gribouillis

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'

Edited 2 Years Ago by snippsat

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

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]

Edited 2 Years Ago by snippsat

This article has been dead for over six months. Start a new discussion instead.