a simple regex question

John Salerno johnjsal at NOSPAMgmail.com
Fri Mar 31 18:47:10 EST 2006


John Salerno wrote:
> Ok, I'm stuck on another Python challenge question. Apparently what you 
> have to do is search through a huge group of characters and find a 
> single lowercase character that has exactly three uppercase characters 
> on either side of it. Here's what I have so far:
> 
> pattern = '([a-z][A-Z]{3}[a-z][A-Z]{3}[a-z])+'
> print re.search(pattern, mess).groups()
> 
> Not sure if 'groups' is necessary or not.
> 
> Anyway, this returns one matching string, but when I put this letter in 
> as the solution to the problem, I get a message saying "yes, but there 
> are more", so assuming this means that there is more than one character 
> with three caps on either side, is my RE written correctly to find them 
> all? I didn't have the parentheses or + sign at first, but I added them 
> to find all the possible matches, but still only one comes up.
> 
> Thanks.

A quick note: I found nine more matches by using findall() instead of 
search(), but I'm still curious how to write the RE so that it works 
with search, especially since findall wouldn't have returned overlapping 
matches. I guess I didn't write it to properly check multiple times.



More information about the Python-list mailing list