could ildg wrote: > But what should I do if there are more than one hello and I only want > to extract what's before the first "hello". For example, the raw > string is "hi, how are you? hello I'm fine, thank you hello. that's it > hello", I want to extract all the stuff before the first hello?
The simplest solution is to use str.split(): >>> helo = "hi, how are you? HELLO I'm fine, thank you hello. that's it" >>> helo.split("hello", 1)[0] "hi, how are you? HELLO I'm fine, thank you " But regular expressions offer a similar feature: >>> re.compile("hello", re.IGNORECASE).split(helo, 1)[0] 'hi, how are you? ' Peter -- http://mail.python.org/mailman/listinfo/python-list