Efficient String Lookup?

Chris S. chrisks at NOSPAM.udel.edu
Sun Oct 17 09:14:49 CEST 2004

Chris S. wrote:

> Andrew Dalke wrote:
>> Here's the output I got when I ran it
>> abadb?  We've got a 'Antimatter containment field breach' warning!
>> abcdef?  We've got a 'Reactor meltdown imminent' warning!
>> zxc?  That's okay.
>> abcq?  We've got a 'Antimatter containment field breach' warning!
>> b1234f?  We've got a 'Coffee too strong' warning!
> Actually, I've noticed some strange behavior. It seems to match more 
> than one character per wild card. For instance, your code matches 
> 'abaxile', 'abaze', and 'abbacomes' to the pattern 'ab##'. I'm not an 
> expert with rex, but your expression looks correct. What could be 
> causing this?

Spoke too soon. I seems all you needed was to change:

full_regexp = "|".join(as_regexps) + "$"


full_regexp = "$|".join(as_regexps) + "$"

However, I noticed rex still doesn't return multiple matches. For 
instance, matching 'abc' to the given the patterns '#bc', 'a#c', and 
'ab#', your code only returns a match to the first pattern '#bc'. Is 
this standard behavior or is it possible to change this?

More information about the Python-list mailing list