On 08/28/10 11:14, agnibhu wrote:
For example say I've key words like abc: bcd: cde: like that... So the
user may use like
abc: How are you bcd: I'm fine cde: ok
So I've to extract the "How are you" and "I'm fine" and "ok"..and
assign them to abc:, bcd: and cde: respectively..
For this, you can do something like
>>> s = "abc: how are you bcd: I'm fine cde: ok"
>>> import re
>>> r = re.compile(r'(\w+):\s*((?:[^:](?!\w+:))*)')
>>> r.findall(s)
[('abc', 'how are you'), ('bcd', "I'm fine"), ('cde', 'ok')]
Yes, it's a bit of a gnarled regexp, but it seems to do the job.
There may be combination of keyowords introduced in future.
like abc: xy: How are you So new keywords qualifying the other
keywords so on.
I'm not sure I understand this bit of what you're asking. If you
have
s = "abc: xy: How are you"
why should that not be parsed as
>>> r.findall("abc: xy: How are you")
[('abc', ''), ('xy', 'How are you')]
as your initial description prescribes?
-tkc
--
http://mail.python.org/mailman/listinfo/python-list