• [^] # Re: raw string

    Posté par (site web personnel) . En réponse au message Python, substitution et regex. Évalué à 3.

    Ha ben faut donner le problème en entier aussi :)

    C'est un peu bourrin, mais ça marche :

    In [19]: re.sub('pattern', re.sub(r'\\', r'\\\\', "\\test") , 'replace the pattern by \\test')
    Out[19]: 'replace the \\test by \\test'
    In [20]: re.sub('pattern', re.sub(r'\\', r'\\\\', "\\nest") , 'replace the pattern by \\test')
    Out[20]: 'replace the \\nest by \\test'
    In [21]: re.sub('pattern', re.sub(r'\\', r'\\\\', "\\lest") , 'replace the pattern by \\test')
    Out[21]: 'replace the \\lest by \\test'
    
    

    tu peux aussi convertir ta chaine en raw string :
    http://code.activestate.com/recipes/65211-convert-a-string-into-a-raw-string/

    Par contre je sais pas vraiment quelle est la différence en terme de résultat entre les deux méthode...

    Matthieu Gautier|irc:starmad