Where's the error?

Duncan Booth duncan at NOSPAMrcp.co.uk
Tue Dec 4 07:21:40 EST 2001


"Bror Johansson" <bror.johansson at avionics.saab.se> wrote in
news:9uibrc$199$1 at newstoo.ericsson.se: 

>     regline =
> re.compile('^(\*)?\s+\\([^\s]+)\s+\\\\([^\s]+)\s+(p(rivate)|(ublic))\s*
> $') 
> 
> Can anyone help me clear my eyesight?
> 

I suggest you either try using raw strings here, or you escape all the 
backslashes. If you copy the string into a variable and print it you should 
see the problem pretty quickly:

>>> s = '^(\*)?\s+\\([^\s]+)\s+\\\\([^\s]+)\s+(p(rivate)|(ublic))\s*$'
>>> s
'^(\\*)?\\s+\\([^\\s]+)\\s+\\\\([^\\s]+)\\s+(p(rivate)|(ublic))\\s*$'
>>> print s
^(\*)?\s+\([^\s]+)\s+\\([^\s]+)\s+(p(rivate)|(ublic))\s*$
>>>

It looks to me as though the second ( is escaped in the regular expression, 
but the second ) is not.

-- 
Duncan Booth                                             duncan at rcp.co.uk
int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3"
"\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure?



More information about the Python-list mailing list