4

I want to extract the name from the following input which is of 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 the quotes as shown below. Any suggestions?

name
Tale
List
Cyrus
  • 84,225
  • 14
  • 89
  • 153
user3570187
  • 1,743
  • 3
  • 17
  • 34

2 Answers2

3

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
akrun
  • 874,273
  • 37
  • 540
  • 662
1

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

Example:

transform(data.frame(name), name = gsub("name\":|\"", "", name))
##   name
## 1 Tale
## 2 List
A5C1D2H2I1M1N2O1R2T1
  • 190,393
  • 28
  • 405
  • 485