[docs] Small suggestion, regular expressions

Georg Brandl georg at python.org
Fri Jul 16 22:19:19 CEST 2010


Am 12.07.2010 08:12, schrieb Ben Fisher:
> Hi,
> I have a small suggestion in Python docs, Standard library, section 7.2 re.
> One of the examples 7.2.6.6. currently reads
>>>> text = "Professor Abdolmalek, please report your absences promptly."
>>>> re.sub("(\w)(\w+)(\w)", repl, text)
> 'Poefsrosr Aealmlobdk, pslaee reorpt your abnseces plmrptoy.'
>>>> re.sub("(\w)(\w+)(\w)", repl, text)
> 'Pofsroser Aodlambelk, plasee reoprt yuor asnebces potlmrpy.'
> 
> I would suggest that the string literals be instead written
>>>> re.sub(r"(\w)(\w+)(\w)", repl, text)
> 'Poefsrosr Aealmlobdk, pslaee reorpt your abnseces plmrptoy.'
>>>> re.sub(r"(\w)(\w+)(\w)", repl, text)
> 'Pofsroser Aodlambelk, plasee reoprt yuor asnebces potlmrpy.'
> with the r in front, even though this doesn't change the code's behavior.
> In this way it would correspond with 7.2.6.7. and is better practice
> in my opinion.

Hi Ben,

thanks for the suggestion, that is indeed the better way to write
these regexes.  Should be corrected now and will be online soon.

regards,
Georg


More information about the docs mailing list