Extract words between double quotes in variable R

I want to extract the name from the following input, which has the form as shown in brackets

# Example of the input in brackets('name":"Tale")
name<- c('name":"Tale"','name":"List"')

I want to extract the names between quotation marks as shown below. Any suggestions?

name
Tale
List
+4
source share
2 answers

Convert the vector to a single column data.frame, and then just use gsubto remove name":and "from the row.

Example:

transform(data.frame(name), name = gsub("name\":|\"", "", name))
##   name
## 1 Tale
## 2 List
+1
source

We could use stri_extract_last_words

library(stringi)
library(data.table)
setDT(list(name=stri_extract_last_words(name)))[]
#   name
#1: Tale
#2: List
+3
source

Source: https://habr.com/ru/post/1617539/


All Articles