split string saving screened spaces
Paul McGuire
ptmcg at austin.rr.com
Fri Dec 16 08:34:29 EST 2005
Pyparsing has built-in quoted string support.
from pyparsing import OneOrMore,Word,alphanums,quotedString
item = Word('-',alphanums) | quotedString | Word(alphanums)
items = OneOrMore(item)
print items.parseString( "-a -b -c '1 2 3' -d 5 -e zork2000" )
gives:
['-a', '-b', '-c', "'1 2 3'", '-d', '5', '-e', 'zork2000']
Download pyparsing at http://pyparsing.sourceforge.net.
-- Paul
More information about the Python-list
mailing list