re.sub() backreference bug?

jeff emminger jemminger at gmail.com
Thu Aug 17 20:47:15 EDT 2006


thanks - that's the trick.

On 8/17/06, Tim Chase <python.list at tim.thechases.com> wrote:
> Looks like you need to be using "raw" strings for your
> replacements as well:
>
> s = re.sub(r'([A-Z]+)([A-Z][a-z])', r"\1_\2", s)
> s = re.sub(r'([a-z\d])([A-Z])', r"\1_\2", s)
>
> This should allow the backslashes to be parsed as backslashes,
> not as escape-sequences (which in this case are likely getting
> interpreted as octal numbers)
>
> -tkc
>



More information about the Python-list mailing list