Efficient String Lookup?

Andrew Dalke adalke at mindspring.com
Sun Oct 17 11:26:27 CEST 2004

Chris S. wrote:
> 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?

It's matching the prefix.  To make it match the string and
only the string you need a $.  Either do

   (pat1$)|(pat2$)| ... |(patN$)

or do

   ((pat1)|(pat2)| ... |(patN))$

If you do the last, don't forget to omit group(1) in
the list of results, or use the non-capturing group
notation, which I believe is (?:  ... ) as in

   (?:(pat1)|(pat2)| ... |(patN))$

				dalke at dalkescientific.com

More information about the Python-list mailing list