On Mon, 9 Jan 2006 13:59:44 +0800, Leo Jay <[EMAIL PROTECTED]> wrote:
>I want to split a string like this: >'abc def "this is a test" ok' >into: >['abc', 'def', 'this is a test', 'ok'] > >is there any lib meet my need? > Narrowly interpreting your requirements (only quotes are with double quotes (never containing escaped same) and strip quotes off) and tested only as you see ;-) >>> import re >>> rx = re.compile(r'"([^"]*)"|(\w+)') >>> s = 'abc def "this is a test" ok' >>> [a or b for a,b in rx.findall(s)] ['abc', 'def', 'this is a test', 'ok'] Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list