Re: re.sub unexpected behaviour

2010-07-06 Thread Javier Collado
Thanks for your answers. They helped me to realize that I was mistakenly using match.string (the whole string) when I should be using math.group(0) (the whole match). Best regards, Javier -- http://mail.python.org/mailman/listinfo/python-list

Re: re.sub unexpected behaviour

2010-07-06 Thread Steven D'Aprano
On Tue, 06 Jul 2010 19:10:17 +0200, Javier Collado wrote: > Hello, > > Let's imagine that we have a simple function that generates a > replacement for a regular expression: > > def process(match): > return match.string > > If we use that simple function with re.sub using a simple pattern an

Re: re.sub unexpected behaviour

2010-07-06 Thread Thomas Jollans
On 07/06/2010 07:10 PM, Javier Collado wrote: > Hello, > > Let's imagine that we have a simple function that generates a > replacement for a regular expression: > > def process(match): > return match.string > > If we use that simple function with re.sub using a simple pattern and > a string

re.sub unexpected behaviour

2010-07-06 Thread Javier Collado
Hello, Let's imagine that we have a simple function that generates a replacement for a regular expression: def process(match): return match.string If we use that simple function with re.sub using a simple pattern and a string we get the expected output: re.sub('123', process, '123') '123' H