[Tutor] using re
Kent Johnson
kent37 at tds.net
Mon Jun 4 12:10:50 CEST 2007
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
More information about the Tutor
mailing list