[Tutor] problem in replacing regex

spir denis.spir at free.fr
Mon Apr 6 17:06:36 CEST 2009


Le Mon, 6 Apr 2009 19:53:25 +0530,
Kumar <hihiren1 at gmail.com> s'exprima ainsi:

> Hello everyone,
> 
> I have one account number. I want to replace all this account numbers and
> convert them as URLS.
> 
> but I don't want to convert existing urls which has account numbers.

[...]

I'm not sure of what you expect, what you try, what you get. Probably you could be more helpful in providing examples of all of that.

> but problem is that if the value is http://sadfsdf.com/1234-4578 then it
> first converts http://sadfsdf.com/1234-4578 into <a href="
> http://sadfsdf.com/1234-4578">http://sadfsdf.com/1234-4578</a> and then
> again it converts last number into url so the complete url gets broken.

What I'm sure is that there's something wrong in what you state above. regex.sub() works as expected even with a replacement substring that matches the pattern:

>>> import re
>>> print re.sub('x', 'x--x', "___x___x___")
'___x--x___x--x___'

[call: re.sub(format, replacement, source)]
As you see, 'x' in the replacement substring will *not* be re-matched and re-replaced.
Maybe I did not understand your issue?

> Thanks,
> Kumar

denis
------
la vita e estrany


More information about the Tutor mailing list