?Module re documentation bug, error, or misunderstanding?

Norman Shelley Norman_Shelley-RRDN60 at email.sps.mot.com
Fri Jul 26 17:28:59 EDT 2002


Thanks Skip.

This solution leads to another question, probably a documentation issue.
I do not need "r"  or double backslashes when I use \d, \s, \S, ... all the
special sequences that  \number  is included  with  in the documentation.  What
indication is there in the documentation that   \number   must be handled
differently than say,  \d  ?

>>> re.match("(.+) \1", '55 55')
>>> re.match("(.+) \\1", '55 55')
<SRE_Match object at 4005c460>
>>> re.match("(.+) (\d\d)", '55 55').groups()         <<<<   \d works with only
one backslash
('55', '55')


Skip Montanaro wrote:

>     Norman> So, what am I missing below as both searches "should" succeed?
>
> "r".
>
> >>> import re
> >>> re.search("(.+) \1", '55 55')
> >>> re.search(r"(.+) \1", '55 55')
> <_sre.SRE_Match object at 0x402665a0>
>
> <wink>
>
> --
> Skip Montanaro
> skip at pobox.com
> consulting: http://manatee.mojam.com/~skip/resume.html





More information about the Python-list mailing list