Regular Expressions and Python 1.5.2

Duncan Booth duncan at rcp.co.uk
Thu Mar 15 05:09:06 EST 2001


Alexandre Fayolle <alf at leo.logilab.fr> wrote in <98q0k8$2b77$1
@norfair.nerim.net>:

>Is this a known bug in the module re of python 1.5.2, or am I missing 
>something obvious?
>
>>>> import re
>>>> t = "m&n"
>>>> re.sub('[^/_ -]','*',t)
>'***'
>>>> re.sub('[^_ -/]','*',t)
>'*&*'
>
I think you are missing something obvious. You specified a range from space 
to '/', and the ampersand is in that range, so it doesn't get replaced. In 
the first example the dash doesn't form part of a range so it is treated 
literally.



More information about the Python-list mailing list