Reputation: 2816
Trying to extract keywords from a string in R but so far unable to find a solution
Giving the string
"erj\"abc\"ejwojeowje \"123\"fjoejfoejf"
How to extract the keywords "abc"
and "123"
into a character vector?
I tried using strsplit
based on \"
but it would also return other unnecessary keywords.
Upvotes: 1
Views: 75
Reputation: 887241
We can try sub
scan(text=sub('[^"]+"([^"]+)"[^"]+"(\\d+).*',
"\\1 \\2", str1), what='')
#[1] "abc" "123"
str1 <- "erj\"abc\"ejwojeowje \"123\"fjoejfoejf"
Upvotes: 1