Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 201839

Return all elements of a string except a substring in R

$
0
0

I'm trying to extract all elements of a string except for a designated substring. I would like to extract everything except the words select and from, and everything in between. I can extract the substring, but I can't figure out how to extract everything except the substring.

a <- "10 bananas select green apples from fruit where (select pears from apples order by fruit)"

#I can successfully extract the substrings using the following code, but I'm looking for the opposite: 
str_extract_all(a, "select.*?from")

#expected output
a<-"10 bananas fruit where ( apples order by fruit)"

Viewing all articles
Browse latest Browse all 201839

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>