split a string of space separated substrings - elegant solution?

Helmut Jarausch jarausch at skynet.be
Tue Jul 31 22:30:34 CEST 2007


I'm looking for an elegant solution to the following (quite common)

Given a string of substrings separated by white space,
split this into tuple/list of elements.
The problem are quoted substrings like

abc "xy z"  "1 2 3"  "a \" x"

should be split into  ('abc','xy z','1 2 3','a " x')

For that, one probably has to protect white space between
quotes, then split by white space and finally converted the
'protected white space' to normal white space again.
Is there an elegant solution - perhaps without using a lexer
and something else. With regular expressions alone it seems

Many thanks for a hint,

Helmut Jarausch

Lehrstuhl fuer Numerische Mathematik
RWTH - Aachen University
D 52056 Aachen, Germany

More information about the Python-list mailing list