Extracting text between double quotation marks in R

Viewed 394

I have a cell with text ["bestsellers","mysteries_thrillers_true_crime","science_fiction_fantasy","literary_fiction"]

The desired outcome is all the types in the cell:

    [1]"bestsellers"
    [2]"mysteries_thrillers_true_crime" 
    [3]"science_fiction_fantasy"
    [4]"literary_fiction"

To extract the text between the double quotation marks, I tried

str_extract(data$preferences[1], "\\[\".*?\"\\]")

and

str_extract(data$preferences[1], "\".*?\"")

both got the result:

 [1] "[\"bestsellers\",\"mysteries_thrillers_true_crime\",\"science_fiction_fantasy\",\"literary_fiction\"]

My question is how to get rid of the [ and ] and get the desire outcome?

0 Answers
Related