Extract text between double quotes in R

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

Desired result - all types in a cell:

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

      

To extract the text between double quotes, 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 [and] and get the result of desire?

+3
regex r stringr data-cleaning


source to share


No one has answered this question yet

See similar questions:

74
Parsing JSON with R

or similar:

343
How to extract a substring using regular expression
15
Replace double quotes with quotes
2
Quote Regex without quotes
0
RegEx: Capturing values ​​between unexperienced quotes
0
Regex.Replace leaving one quote behind
0
Regex: choosing between quotes with positive lookbehind
0
Extracting values ​​between commas without quotes
0
Extract text between quotes from file in notepad ++
-2
How to extract text between quotes in R
-2
Regular expression in R to capture information within subsequent quotes



All Articles
Loading...
X
Show
Funny
Dev
Pics