Isn't re.findall supposed to find all?

Rodrigo Senra rodsenra at correionet.com.br
Sat Nov 11 18:08:21 EST 2000


For those who hasve just arrived:

Problem Statement: 

 Find re that match string headed by XYZ and tailed by PQR without
 any LMN in between.


Changjun Kim wrote:
> 
> ----- Original Message -----
> From: "Rodrigo Senra" <rodsenra at correionet.com.br>
> > r'(XYZ[\w\s]*?[^LMN][\w\s]*?QPR)
> > raw=head + non-greedy-stuff + avoid-LMN + non-greedy-stuff + tail
> > regards
> > Rod
> > --
> 
> It does not work properly.

Those re's are tricky devils! You are right that was wrong(yin/yang).

Trying to fix it I came up with:
 p = re.compile(r'(XYZ.*?(?!LMN).*?PQR)')

But that does not solve it either. Does anybody know why ?
Anyway, instead of fighting this I would do something like:

 z = '...<the malicious string>...'
 p = re.compile(r'(XYZ.*PQR)')
 result= (filter(lambda x:x.find('LMN')<0,p.findall(z)))

Though I became curious about it now!
[]'s
Rod
-- 
Rodrigo Senra         
Computer Engineer   (GPr Sistemas Ltda)  rodsenra at correionet.com.br 
MSc Student of Reflection (IC- UNICAMP) Rodrigo.Senra at ic.unicamp.br
http://www.ic.unicamp.br/~921234 (see also   http://www.gpr.com.br)





More information about the Python-list mailing list