[Tutor] using re

Roel Schroeven rschroev_nospam_ml at fastmail.fm
Mon Jun 4 11:04:59 CEST 2007


johnf schreef:
> I have the following
> pattern='^([0-9]{0,%s})(\.[0-9]{0,%s})?$' % (self.IntegerWidth, 
> self.DecimalWidth)
> )
> 	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?

It's because of the 0 in {0,%s} in the first part of you regular 
expression. That 0 means that the pattern matches numbers without 
integer part.

You just need to change that 0 to a 1, as follows:

^([0-9]{&,%s})(\.[0-9]{0,%s})?$

-- 
If I have been able to see further, it was only because I stood
on the shoulders of giants.  -- Isaac Newton

Roel Schroeven



More information about the Tutor mailing list