I have a python string, which contains a number of strings. I want to write a function that extracts strings out of a given string. I'll explain this using an example :
I have this string
'"Row Number","Status","Timestamp","Requestor, Email, id"'
As one can see, This string contains many strings, which are represented inside double quotes("")
. I want to write a function that takes as input this string and return the following list to me.
['Row Number', 'Status', 'Timestamp', 'Requestor, Email, id']
Currently, I have very trivial logic. I split the string at "
, and then I process a weird list like the following to get my desired list.
['', 'Row Number', ',', 'Status', ',', 'Timestamp', ',', 'Requestor, Email, id', '']
I pick odd indexed items from this list to get my desired list. I wanted to know if there is any better approach to solve this problem. For example, maybe using re
, we can get this using a single line of code? Or something else?
Edit : I'm not reading any csv file, or my data is not coming from any csv source. This data is coming from google sheets API. I can not use any functions like read_csv
or separate the string at commas. This is not possible since certain strings inside the string also contain the comma. SO, I MUST EXTRACT ALL THE STRINGS INSIDE ""
first.