split a string of space separated substrings - elegant solution?
- From: Helmut Jarausch <jarausch@xxxxxxxxx>
- Date: Tue, 31 Jul 2007 22:30:34 +0200
Hi,
I'm looking for an elegant solution to the following (quite common)
problem:
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
clumsy.
Many thanks for a hint,
Helmut Jarausch
Lehrstuhl fuer Numerische Mathematik
RWTH - Aachen University
D 52056 Aachen, Germany
.
- Follow-Ups:
- Re: split a string of space separated substrings - elegant solution?
- From: Jerry Hill
- Re: split a string of space separated substrings - elegant solution?
- From: Carsten Haese
- Re: split a string of space separated substrings - elegant solution?
- From: Wojciech Muła
- Re: split a string of space separated substrings - elegant solution?
- Prev by Date: Re: Subprocess and pipe-fork-exec primitive
- Next by Date: Re: encode() question
- Previous by thread: Extending Python by Adding Keywords & Data types
- Next by thread: Re: split a string of space separated substrings - elegant solution?
- Index(es):
Relevant Pages
|