[Tutor] using re

johnf jfabiani at yolo.com
Mon Jun 4 15:57:25 CEST 2007


On Monday 04 June 2007 03:10, you wrote:
> johnf wrote:
> > I have the following
> > pattern='^([0-9]{0,%s})(\.[0-9]{0,%s})?$' % (self.IntegerWidth,
> > self.DecimalWidth)
>
> You should use a raw string (prefix with r) to define pattern, though
> that isn't the problem here.
>
> > )
> > 	if re.match(pattern, self.GetValue())==None:
> > 	    self.BackColor == "pink"
> > 	else:
> > 	    self.BackColor == "white"
> >
> > self.IntegerWidth = 2
> > self.DecimalWidth=2
> >
> > the problem is the pattern allows ".999".  What am I doing wrong?
>
> Are you sure? That's not what I get:
>
> In [3]: pattern='^([0-9]{0,%s})(\.[0-9]{0,%s})?$' % (2, 2)
> In [5]: import re
> In [9]: print re.match(pattern, '.99')
> <_sre.SRE_Match object at 0x1280218>
> In [10]: print re.match(pattern, '.999')
> None
>
> Kent
Thanks for you response.  You are correct and I have determined that something 
is wrong with the "self.BackColor == "pink" " statement because it does not 
turn the background pink but is firing.  
-- 
John Fabiani


More information about the Tutor mailing list