Boy do REs ever suck sometimes...
Richard Jones
richard at bizarsoftware.com.au
Fri Oct 5 02:51:44 EDT 2001
On Friday 05 October 2001 16:45, Ignacio Vazquez-Abrams wrote:
> Here's the problem I'm having with REs. When I use an RE like '^[0-9]+$' it
> matches both '123' and '123\n'. How can I get it to not match the string
> with the newline?
Is this any help?
>>> re.match('^[\d]+$', '123')
<SRE_Match object at 0x8157570>
>>> re.match('^[\d]+$', '123\n')
<SRE_Match object at 0x8158ee0>
>>> re.match('^[\d]+$', '123').end()
3
>>> re.match('^[\d]+$', '123\n').end()
3
Richard
More information about the Python-list
mailing list