3 new slogans

Skip Montanaro skip at pobox.com
Thu Aug 14 14:45:20 CEST 2003


    >> s/(perl|java|vba|c(#|\+\+|)?)/python/g

    Michael> .. but - as *any* regex - can be improved:
    Michael>   s/\b(perl|java|vba?|c(#|\+\+|)?)/python/gi

We ought to at least use Python for this

    re.sub(r"(?i)\b(perl|java|vba?|c(#|\+\+|)?)", "python")

    >>> import re
    >>> s = "vba vb perl java vba vb c# c c++"
    >>> re.sub(r"(?i)\b(perl|java|vba?|c(#|\+\+)?)", "python", s)      
    'python python python python python python python python python'

Skip





More information about the Python-list mailing list