I’m trying to split a string looking like this in Python using re.split:
#NAME="Foo" NAME2="foobar" NAME3="BAR BAR"
comp = "NAME=\"Foo\" NAME2=\"FOO BAR\" NAME3=\"BAR BAR\""
This is how my split-function including regex looks like:
re.split('(\s\w+\=\".*?\")', comp)
The result looks like this:
['NAME="Foo"', 'NAME2="foobar"', '', 'NAME3="BAR BAR"', '']
While this is correct I’d like to get rid of all empty elements.
Is this what you’re looking for:
?
It doesn’t sound like
re.split()is the right tool for the job.