regular expression for space seperated quoted string
Padraig Brady
Padraig at Linux.ie
Wed Sep 11 09:13:31 EDT 2002
Eric Brunel wrote:
> Padraig Brady wrote:
>
>
>>Hi, I'm trying to split a string that is seperated
>>by spaces and also contains double quoted words which
>>can contain spaces:
[snip]
> What about:
>
>>>>p = r'[^ \t\n\v\f"]+|"[^"]*"'
>>>>re.findall(p, '1 2 3')
FYI, I'm using the following:
import fileinput, re
for line in fileinput.input():
#split fields
fields = re.findall('[^ "]+|"[^"]+"', line[:-1])
#remove quotes
fields = map(lambda field: field.replace('"', ''), listLine)
thanks again,
Pádraig.
More information about the Python-list
mailing list