Boy do REs ever suck sometimes...

Ignacio Vazquez-Abrams ignacio at openservices.net
Fri Oct 5 02:57:39 EDT 2001


On Fri, 5 Oct 2001, Richard Jones wrote:

> 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

Unfortunately not, because I'd rather not have it match at all if there's a
newline. I can special-case it in my code; I was just hoping that I wouldn't
have to.

-- 
Ignacio Vazquez-Abrams  <ignacio at openservices.net>





More information about the Python-list mailing list