Splitting a string by spaces without space-splitting elements in double-quotes
The best way to do what you want with the standard library would be shlex.split():

&gt;&gt;&gt; import shlex
&gt;&gt;&gt; s = r'  "C:\Program Files (x86)\myeditor" "$FILEPATH" -n$LINENO "c:\Program Files" -f$FILENAME -aArg2'
&gt;&gt;&gt; shlex.split(s)
['C:\\Program Files (x86)\\myeditor', '$FILEPATH', '-n$LINENO', 'c:\\Program Files', '-f$FILENAME', '-aArg2']


Note that the quotes are not retained.