python re.sub

Fredrik Lundh fredrik at pythonware.com
Thu May 6 18:09:04 EDT 1999


Andrew M. Kuchling wrote:
> Ivan Van Laningham writes:
> >"Jerry L. Bash" wrote:
> >> At any rate, the following is mostly taken from the HOWTO.  It appears
> >> that the default 'count' is not working as I expected, resulting in
> >> not making substitutions for all cases.
> >> 
> >> Python 1.5.2 (#2, Apr 26 1999, 09:21:48)  [GCC 2.8.1] on irix646
> >> Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
> >> >>> import re
> >> >>> p = re.compile( '(blue|white|red)')
> >> >>> p.sub( 'colour', 'blue socks and red shoes')
> >> 'blue socks and red shoes'
> 
> After looking at re.py a bit, here's a suggestion: What does
> 'import sys ; print sys.maxint' output?  The re.py code contains a
> statement like "if count==0: count = sys.maxint", and I'm wondering if
> perhaps sys.maxint is coming out negative, which would explain these
> symptoms.  Why sys.maxint might be negative, I don't know.

according to:
http://www.dejanews.com/getdoc.xp?AN=401964035
it's -1.  that post also has a solution to the problem.

also see:
http://www.dejanews.com/getdoc.xp?AN=366297402

</F>





More information about the Python-list mailing list