I have a string which is like this:
this is \"a test\"
I\'m trying to write something in Python to split it up by space while ignoring spac
I suggest:
test string:
s = 'abc "ad" \'fg\' "kk\'rdt\'" zzz"34"zzz "" \'\''
to capture also "" and '':
import re
re.findall(r'"[^"]*"|\'[^\']*\'|[^"\'\s]+',s)
result:
['abc', '"ad"', "'fg'", '"kk\'rdt\'"', 'zzz', '"34"', 'zzz', '""', "''"]
to ignore empty "" and '':
import re
re.findall(r'"[^"]+"|\'[^\']+\'|[^"\'\s]+',s)
result:
['abc', '"ad"', "'fg'", '"kk\'rdt\'"', 'zzz', '"34"', 'zzz']