3

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?

rrrcr
  • 31
  • 1
  • 4
    `jsonlite::fromJSON('["bestsellers","mysteries_thrillers_true_crime","science_fiction_fantasy","literary_fiction"]')` – alistaire May 14 '17 at 05:55
  • 1
    Do _not_ use regex here, use a JSON parser/library instead, q.v. the above comment. – Tim Biegeleisen May 14 '17 at 05:57
  • @rrrcr Clarification required. Do you want to get a regex for extracting only the text between double quotes contained in this string - ["bestsellers","mysteries_thrillers_true_crime","science_fiction_fantasy","literary_fiction"] ? – Gurmanjot Singh May 14 '17 at 06:22

0 Answers0