4
Contributors
8
Replies
64
Views
2 Years
Discussion Span
Last Post by silverdust
Featured Replies
  • You can perhaps add the condition that there is no uppercase letter before the first 3 ones or after the 3 last ones. Read More

  • > 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 … Read More

  • > 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]` Read More

1

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

Edited by Gribouillis

1

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 by snippsat

0

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

0

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

2

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 by snippsat

This article has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.