Antoon Pardon wrote:
> On 2008-12-31, TP wrote:
>> Hi everybody,
>>
>> I would like to change only the nth occurence of a pattern in a
string. The
>> problem with "replace" method of strings, and "re.sub" is that we
can only
>> define the number of occurrences to change from the first one.
>>
On 2008-12-31, TP wrote:
> Hi everybody,
>
> I would like to change only the nth occurence of a pattern in a string. The
> problem with "replace" method of strings, and "re.sub" is that we can only
> define the number of occurrences to change from the first one.
>
v="coucou"
v.replace("o
I would like to change only the nth occurence of a pattern in
a string. The problem with "replace" method of strings, and
"re.sub" is that we can only define the number of occurrences
to change from the first one.
v="coucou"
v.replace("o","i",2)
'ciuciu'
import re
re.sub( "o", "i", v,2)
'c
On Wed, 31 Dec 2008 15:40:32 +0100, TP wrote:
> Hi everybody,
>
> I would like to change only the nth occurence of a pattern in a string.
> The problem with "replace" method of strings, and "re.sub" is that we
> can only define the number of occurrences to change from the first one.
>
v="co
In article <0scs26-7a5@rama.fbx.proxad.net>,
TP wrote:
> Hi everybody,
>
> I would like to change only the nth occurence of a pattern in a string.
It's a little ugly, but the following looks like it works. The gist is to
split the string on your pattern, then re-join the pieces using the
Hi everybody,
I would like to change only the nth occurence of a pattern in a string. The
problem with "replace" method of strings, and "re.sub" is that we can only
define the number of occurrences to change from the first one.
>>> v="coucou"
>>> v.replace("o","i",2)
'ciuciu'
>>> import re
>>> re