On Mon, 10 Sep 2007 00:29:50 -0700, Ant wrote:
> On Sep 10, 3:15 am, "a.m." <[EMAIL PROTECTED]> wrote:
>> Thanks guys for you help. I ended up doing this way (for the
>> records)...
>>
>> t1 = "hello world hello. hello. \nwhy world hello"
> ...
>
> Another approach may be to use the re module's sub function:
>
> import re
>
> t1 = 'hello world hello. hello. \nwhy world hello'
>
> def matchHandler(match):
> if <test here>:
> return "XYZ" + match.group(0)
> else:
> return match.group(0)
>
> re.sub(keyword, matchHandler, t1)
This doesn't work because according to the OP not all 'hello's are
keywords. It seems to depend on the position if it's a keyword or not.
Ciao,
Marc 'BlackJack' Rintsch
--
http://mail.python.org/mailman/listinfo/python-list