Suggestion for a new regular expression extension

darrell dgallion at yahoo.com
Thu Nov 27 17:31:41 CET 2003


If you can make re.sub work for you...

import re
pat="B(?:D|LD|VD|OUL(?:EVARD)?)"
input="BD, BLD, BVD, BOUL, BOULEVARD.".split()

for i in input:
     print i, "::", re.sub(pat, "BD", i)

BD, :: BD,
BLD, :: BD,
BVD, :: BD,
BOUL, :: BD,
BOULEVARD. :: BD.


For more complex cases you can pass a function instead of the 
replacement string.


--Darrell





More information about the Python-list mailing list